Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
width: 180,
height: 180,
includeBase64: true,
// compressImageQuality: 0.2,
mediaType: 'photo',
};
// loading UI to account for the delay after picking an image
setTimeout(
() =>
this.setState({
imagePicking: true,
}),
1000,
);
ImagePicker.openPicker(options)
.then((image) => {
const imageData = { uri: `data:${image.mime};base64,${image.data}` };
this.setState({
userAvatar: imageData,
imagePicking: false,
});
setTimeout(
() =>
this.setState({
imagePicking: false,
}),
1001,
);
})
.catch((err) => {
console.log(err);
function openPicker (options) {
console.log(options)
const {count: maxFiles, success, complete} = options
return ImagePicker.openPicker({
multiple: true,
maxFiles
}).then(images => {
console.log(images)
let data = Object.assign({}, getRes(images), res)
success && success(data)
complete && complete(data)
return data
})
}
pickImage = async() => {
const options = {
cropping: true,
compressImageQuality: 0.8,
cropperAvoidEmptySpaceAroundImage: false,
cropperChooseText: I18n.t('Choose'),
cropperCancelText: I18n.t('Cancel'),
includeBase64: true
};
try {
const response = await ImagePicker.openPicker(options);
this.setAvatar({ url: response.path, data: `data:image/jpeg;base64,${ response.data }`, service: 'upload' });
} catch (error) {
console.warn(error);
}
}
export const getGalleryMediaObject = async (
options: Partial = {},
): Promise => {
try {
const mediaObject: IPickerImage | IPickerImage[] = await ImagePicker.openPicker({
...DEFAULT_PICKER_OPTIONS,
...options,
});
return mediaObject as IPickerImage;
} catch (ex) {
console.log('getGalleryMediaObject error', ex);
}
};
onChooseFromGalleryPress() {
ImagePicker.openPicker({
width: Constants.UPLOAD_POST_PICTURE_SIZE,
height: Constants.UPLOAD_POST_PICTURE_SIZE,
cropping: true,
})
.then((image) => {
const imageSource = extractImageSource(image);
this.setState({
imageFile: image,
imageSource,
});
});
}
onChooseFromGalleryPress() {
ImagePicker.openPicker({
width: Constants.UPLOAD_POST_PICTURE_SIZE,
height: Constants.UPLOAD_POST_PICTURE_SIZE,
cropping: true,
avoidEmptySpaceAroundImage: false,
cropperStatusBarColor: Colors.BASE,
cropperToolbarColor: Colors.BASE,
})
.then((image) => {
const imageSource = extractImageSource(image);
this.props.changeImage(imageSource);
});
}
private _onAddImageClick = async () => {
const { value } = this.state
const { onChange } = this.props
try {
const images = await ImageCropPicker.openPicker({
multiple: true,
waitAnimationEnd: false,
includeExif: true,
forceJpg: true,
maxFiles: 9 - value.length,
compressImageQuality: 0.5,
})
let files: any = []
if (Array.isArray(images)) {
files = images.map((item, index) => ({
url: item.path,
id: index,
meta: { ...item },
}))
} else {
files = [
chooseFromLibrary = async() => {
try {
const image = await ImagePicker.openPicker(this.libraryPickerConfig);
this.showUploadModal(image);
} catch (e) {
log(e);
}
}
const handlePicturePressed = async () => {
try {
const pic = await ImagePicker.openPicker({
width: 400,
height: 400,
cropping: true,
cropperCircleOverlay: true,
mediaType: 'photo',
})
if (pic) {
dispatch({ type: 'SET_PICTURE', pic })
}
} catch (err) {
if (err?.code !== 'E_PICKER_CANCELLED') {
dispatch({ type: 'SET_ERROR', err })
}
}
}