Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Permissions.askAsync(Permissions.CAMERA_ROLL).then((isAllowed) => {
// if (!isAllowed) return
// ImagePicker.launchImageLibraryAsync({
// mediaTypes: 'All'
// })
// .then((result) => {
// console.log(result)
// if (!result.cancelled) {
// this.setState({ file: result })
// this.addFile(result)
// }
// })
// })
ImagePicker.showImagePicker({}, (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 {
const source = {
uri: response.uri
}
// You can also display the image using data:
// const source = { uri: 'data:image/jpeg;base64,' + response.data };
getAvatarPhoto = () => {
// see https://github.com/react-community/react-native-image-picker
// for full documentation on the Image Picker api
const options = {
title: "Select Avatar",
customButtons: [{ name: "fb", title: "Choose Photo from Facebook" }],
storageOptions: {
skipBackup: true,
path: "images"
}
};
ImagePicker.showImagePicker(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 {
let source = { uri: response.uri };
// You can also display the image using data:
// let source = { uri: 'data:image/jpeg;base64,' + response.data };
this.setState({
avatarSource: source
cancelButtonTitle: 'Cancel',
takePhotoButtonTitle: 'Take Photo...',
chooseFromLibraryButtonTitle: 'Choose from Library...',
cameraType: 'front',
mediaType: 'photo',
quality: 0.5,
allowsEditing: true,
noData: !data,
storageOptions: {
skipBackup: true,
path: 'images',
},
...xtra,
};
ImagePicker.showImagePicker(options, response => {
const { error } = response;
if (response.didCancel) {
// Do nothing
} else if (error) {
reject(error);
} else {
if (data && response.data) {
let dataUri = 'data:image/jpeg;base64,' + response.data;
response.dataUri = dataUri;
}
resolve(response);
}
});
});
}
showImagePicker(){ /* select image from camera roll for avatar */
ImagePicker.showImagePicker(ImageOptions, (response) => {
if (response.didCancel || response.error) { return; }
const avatar = 'data:image/png;base64,' + response.data;
this.setState({ avatar });
});
}
selectTechnology(technology){
imagePicker(){
const options = {
quality: 1.0,
storageOptions: {
skipBackup: true,
},
};
ImagePicker.showImagePicker(options, (response) => {
if (response.didCancel) {
console.log('User cancelled photo picker');
} else if (response.error) {
console.log('ImagePicker Error: ', response.error);
} else if (response.customButton) {
console.log('User tapped custom button: ', response.customButton);
} else {
console.log('ImagePicker Response: ',response);
if(Platform.OS === 'ios' && response.fileName != undefined){
var ext = response.fileName.split('.')[1].toLowerCase();
var type = this.getMimeType(ext);
var name = response.fileName;
}else{
var type = response.type;
var name = 'Camera_001.jpeg';
}
_selectPhotoTapped() {
const options = {
quality: 1.0,
maxWidth: 500,
maxHeight: 500,
title:'请选择照片',
takePhotoButtonTitle:'拍照',
chooseFromLibraryButtonTitle:'从照片库中查找',
cancelButtonTitle:'取消',
storageOptions: {
skipBackup: true
}
};
ImagePicker.showImagePicker(options, (response) => {
console.log('Response = ', response);
if (response.didCancel) {
console.log('User cancelled photo picker');
}
else if (response.error) {
console.log('ImagePicker Error: ', response.error);
}
else if (response.customButton) {
console.log('User tapped custom button: ', response.customButton);
}
else {
var source;
if (Platform.OS === 'android') {
source = {uri: response.uri, isStatic: true};
} else {
source = {uri: response.uri.replace('file://', ''), isStatic: true};
return this.governmentPhotoTypeActionSheet.show()
}
title = lndrVerified.chooseGovernmentPhoto
} else if (type === 'selfiePhoto') {
title = lndrVerified.chooseSelfiePhoto
} else {
if (getType) {
return this.addressPhotoTypeActionSheet.show()
}
title = lndrVerified.chooseAddressPhoto
}
let options = {
title,
storageOptions: { skipBackup: true, path: 'images' }
}
ImagePicker.showImagePicker(options, async (response) => {
if (response.didCancel) {
console.log('User cancelled image picker')
} else if (response.error) {
console.log('ImagePicker Error: ', response.error)
} else {
const { uri, data } = response
const photo = await setKYCImage(uri, data)
if (type === 'governmentPhoto') {
this.setState({ governmentPhoto: photo, generalFormError: undefined })
} else if (type === 'selfiePhoto') {
this.setState({ selfiePhoto: photo, generalFormError: undefined })
} else {
this.setState({ addressPhoto: photo, generalFormError: undefined })
}
}
})
selectPhoto() {
console.log("Reached me!");
const options = {
quality: 1.0,
maxWidth: 500,
maxHeight: 500,
storageOptions: {
skipBackup: true
}
};
ImagePicker.showImagePicker(options, (response) => {
console.log('Response = ', response);
if (response.didCancel) {
console.log('User cancelled photo picker');
} else if (response.error) {
console.log('ImagePicker Error: ', response.error);
} else if (response.customButton) {
console.log('User tapped custom button: ', response.customButton);
} else {
var source;
if (Platform.OS === 'android') {
source = {
uri: response.uri,
isStatic: true
};
_handleButtonPress = () => {
ImagePicker.showImagePicker({ title: "Pick an Image", maxWidth: 800, maxHeight: 600 }, res => {
if (res.didCancel) {
console.log("User cancelled!");
} else if (res.error) {
console.log("Error", res.error);
} else {
this.setState({
pickedImage: res.uri,
imageSelected: true
});
}
});
};
reset = () => {
handleUpdateImage = async () => {
const options = {
noData: true,
mediaType: 'photo'
}
ImagePicker.showImagePicker(options, (response) => {
if (response.didCancel) {
console.warn('User cancelled image picker');
} else if (response.error) {
console.warn('ImagePicker Error: ', response.error);
} else if (response.customButton) {
console.warn('User tapped custom button: ', response.customButton);
} else {
const source = { uri: response.uri }
this.setState({
imageProfile: source,
});
}
})
}