Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
chooseFile = async () => {
setTimeout(() => {
this.onToggleLoading()
}, 1000);
const { mediaType = 'Images' } = this.props
let result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions[mediaType],
// mediaTypes: ImagePicker.MediaTypeOptions.All,
allowsEditing: mediaType === 'Images' ? true : false,
base64: true,
quality: 1,
});
if (!result.cancelled) {
const { onChangeCallback, input: { onChange } } = this.props
this.setState({ image: result.uri });
FileSystem.readAsStringAsync(result.uri, {
encoding: FileSystem.EncodingType.Base64
}).then((base64) => {
const res = { ...result, base64 }
onChangeCallback(res)
this.onToggleLoading()
selectImage = async () => {
try {
let response = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions.All,
allowsEditing: true,
aspect: [4, 3]
})
if (!response.cancelled) {
const source = { uri: response.uri }
this.setState({ image: source })
this.classifyImage()
}
} catch (error) {
console.log(error)
}
}
import * as ImagePicker from 'expo-image-picker';
import * as FileSystem from 'expo-file-system';
import * as MediaLibrary from 'expo-media-library';
import * as Permissions from 'expo-permissions';
const mediaOptions = {
allowsEditing: true,
quality: 1.0,
allowsMultipleSelection: false,
mediaTypes: ImagePicker.MediaTypeOptions.Images,
exif: false,
base64: false,
};
const directory = `${FileSystem.documentDirectory}/photos`;
async function ensurePermissionsAsync(): Promise {
const { status } = await Permissions.askAsync(Permissions.CAMERA, Permissions.CAMERA_ROLL);
if (status !== Permissions.PermissionStatus.GRANTED) {
alert(
'Cannot select a banner photo without media access! Please enable the "Camera" & "Camera Roll" permission in your system settings.'
);
return false;
}
return true;
}
onPress={() => {
this.showPicker(ImagePicker.MediaTypeOptions.Images);
}}
title="Pick photo"
onPress={() => this.showPicker(ImagePicker.MediaTypeOptions.Images)}
title="Pick photo"
const mediaTypeToImagePickerMediaType = (
mediaType: 'photo' | 'video' | 'mixed'
): ImagePicker.MediaTypeOptions =>
mediaType === 'photo'
? ImagePicker.MediaTypeOptions.Images
: mediaType === 'video'
? ImagePicker.MediaTypeOptions.Videos
: ImagePicker.MediaTypeOptions.All
const mediaTypeToImagePickerMediaType = (
mediaType: 'photo' | 'video' | 'mixed'
): ImagePicker.MediaTypeOptions =>
mediaType === 'photo'
? ImagePicker.MediaTypeOptions.Images
: mediaType === 'video'
? ImagePicker.MediaTypeOptions.Videos
: ImagePicker.MediaTypeOptions.All
onPress={() => this.showCamera(ImagePicker.MediaTypeOptions.All)}
title="Take photo or video"
const mediaTypeToImagePickerMediaType = (
mediaType: 'photo' | 'video' | 'mixed'
): ImagePicker.MediaTypeOptions =>
mediaType === 'photo'
? ImagePicker.MediaTypeOptions.Images
: mediaType === 'video'
? ImagePicker.MediaTypeOptions.Videos
: ImagePicker.MediaTypeOptions.All