Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
handleImagePicker() {
this.setState({
isEmoji: false
})
ImagePicker.launchImageLibrary(options, (response) => {
console.log('Response = ', response);
if (response.didCancel) {
console.log('User cancelled image picker');
}
else if (response.error) {
console.log('ImagePicker Error: ', response.error);
}
else if (response.customButton) {
console.log('User tapped custom button: ', response.customButton);
}
else {
// You can display the image using either data...
//const source = {uri: 'data:image/jpeg;base64,' + response.data, isStatic: true};
// or a reference to the platform specific asset location
openLibrary() {
// Open Image Library:
ImagePicker.launchImageLibrary(options, (response) => {
// Same code as in above section!
console.log('Response = ', response)
if (response.didCancel) {
console.log('User cancelled image picker')
}
else if (response.error) {
console.log('ImagePicker Error: ', response.error)
}
else if (response.customButton) {
console.log('User tapped custom button: ', response.customButton)
}
else {
// let source = { uri: 'data:image/jpeg;base64,' + response.data };
// console.log('source = ', source);
this.props.route.params.response(response)
onFromPickerImage={()=>{
var options = {
title: 'Select Avatar',
storageOptions: {
skipBackup: true,
path: 'images'
}
};
ImagePicker.launchImageLibrary(options, (response) => {
// Same code as in above section!
let source = { uri: response.data };
if (response.data) {
if (clickedPage =='report') {
this.props.addressActions.addImage({res: response.data});
} else {
this.props.accountActions.addImage({res: response.data});
}
}
});
}}
/>
const onSelectImage = () => {
isUploadingToggle(true)
ImagePicker.launchImageLibrary({
title: translate.t('user.avatar'),
noData: true,
allowsEditing: true,
mediaType: 'photo'
}, async response => {
if (response.didCancel) {
isUploadingToggle(false)
} else if (response.error) {
isUploadingToggle(false)
// Error selecting image
dispatch(messageShow({ success: false, message: translate.t('common.error.default') }))
} else {
// Image selection successful
await uploadImage(response)
fromPicker() {
var options = {
title: 'Select Avatar',
storageOptions: {
skipBackup: true,
path: 'images'
}
};
ImagePicker.launchImageLibrary(options, (response) => {
// Same code as in above section!
let source = { uri: response.data };
if (response.data) {
this.setState(
update(this.state, {
images: {
$push: [{
'backImage': response.data,
'drawImage': ''
}]
},
isCamera: {$set: false},
selectedIndex: {$set: 0},
isDraw: {$set: false}
})
openPhoto(){
console.log('ImagePicker');
ImagePicker.launchImageLibrary({}, (response) => {
console.log('Response = ', response);
if (response.didCancel) {
console.log('User cancelled image picker');
}
else if (response.error) {
console.log('ImagePicker Error: ', response.error);
}
else if (response.customButton) {
console.log('User tapped custom button: ', response.customButton);
}
else {
if(response.uri){
var path = response.path;
if(!path){
path = response.uri;
PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE], () => {
//打开系统相册
ImagePicker.launchImageLibrary(AppConfig.IMAGE_PICKER_OPTIONS, (response) => {
this.dismissOverlay();
//响应结果处理参考上面样例
console.log(response);
if (!response.error && response.uri && this.props.callback) {
this.props.callback({
uri: response.uri,
path: response.path,
fileSize: response.fileSize,
fileName: response.fileName,
width: response.width,
height: response.height,
});
} else {
ToastAI.showShortBottom("打开图库失败");
}
});
onPress={() => {
if (RNCamera.Constants.CameraStatus === RNCamera.Constants.CameraStatus.READY) this.cameraRef.pausePreview();
ImagePicker.launchImageLibrary(
{
title: null,
mediaType: 'photo',
takePhotoButtonTitle: null,
},
response => {
if (response.uri) {
const uri = Platform.OS === 'ios' ? response.uri.toString().replace('file://', '') : response.path.toString();
LocalQRCode.decode(uri, (error, result) => {
if (!error) {
this.onBarCodeRead({ data: result });
} else {
if (RNCamera.Constants.CameraStatus === RNCamera.Constants.CameraStatus.READY) this.cameraRef.resumePreview();
alert('The selected image does not contain a QR Code.');
}
});
showMediaPicker = (type) => {
this.setState({
assetType: type,
asset: null,
loading: true
});
ImagePicker.launchImageLibrary(mediaOptions[type], (response) => {
if (!response.didCancel && !response.error) {
let source = {uri: `data:image/jpeg;base64,${response.data}`, isStatic: true};
if (Platform.OS === 'ios') {
source = {
...source,
path: response.uri.replace('file://', ''),
assetURL: response.origURL,
width: response.width,
height: response.height
};
} else {
source = {
...source,
path: response.path,
width: response.width,
height: response.height
if (response.error) {
this.props.onFilePickerError(new Error(response.error))
return
}
const filename = isIOS ? response.uri.replace('file://', '') : response.path
if (filename) {
this.props.onAttach([filename])
}
}
switch (location) {
case 'camera':
launchCamera({mediaType, permissionDenied, takePhotoButtonTitle, title}, handleSelection)
break
case 'library':
launchImageLibrary({mediaType, permissionDenied, takePhotoButtonTitle, title}, handleSelection)
break
}
}