Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.then((response) => {
const { status, expires, permissions } = response
if (status === 'granted') {
ImagePicker.launchCameraAsync({
// mediaTypes: 'All',
base64: true,
quality: 1,
})
.then((response) => {
if (!response.cancelled) {
const { user, sendImage } = this.props
//TODO: Check if it is a video and store video
const data = { uri: response.uri, user }
sendImage(data)
}
})
.catch((error) => console.log(error))
}
})
.catch((error) => console.log(error))
.then((response) => {
const { status, expires, permissions } = response
if (status === 'granted') {
ImagePicker.launchCameraAsync({
allowsEditing: true,
aspect: [1, 1],
base64: true,
quality: 0.5,
})
.then((response) => {
if (!response.cancelled) {
this.props.uploadImage(response.uri)
}
})
.catch((error) => console.log(error))
}
})
.catch((error) => console.log(error))
.then((response) => {
const { status } = response
if (status === 'granted') {
ImagePicker.launchCameraAsync({
allowsEditing: true,
aspect: [1, 1],
base64: true,
quality: 0.5,
})
.then((response) => {
if (!response.cancelled) {
this.props.uploadImage(response.uri)
}
})
.catch((error) => console.log(error))
}
})
.catch((error) => console.log(error))
return new Promise((resolve, reject) => {
p = isCamera ? ImagePicker.launchCameraAsync(options) : ImagePicker.launchImageLibraryAsync(options)
p.then((resp) => {
const { uri } = resp
resp.path = uri
const res = {
tempFilePaths: [uri],
tempFiles: [resp]
}
success && success(res)
complete && complete(res)
resolve(res)
}).catch((err) => {
const res = {
errMsg: 'chooseImage fail',
err
}
fail && fail(res)
export async function takePhotoAsync(): Promise {
if (!(await ensurePermissionsAsync())) return null;
const media = await ImagePicker.launchCameraAsync(mediaOptions);
if (!media.cancelled) {
const asset = await MediaLibrary.createAssetAsync(media.uri);
return await moveToPhotoCacheAsync(asset.uri);
}
return null;
}
export const launchCameraAsync = (
mediaType: 'photo' | 'video' | 'mixed',
askPermAndRetry: boolean = true
): Promise => {
return ImagePicker.launchCameraAsync({mediaTypes: mediaTypeToImagePickerMediaType(mediaType)}).catch(
retyAfterAskingPerm(
[Permissions.CAMERA, Permissions.CAMERA_ROLL],
askPermAndRetry ? () => launchCameraAsync(mediaType, false) : null
)
)
}
export async function takePictureAsync(onSend) {
if (await getPermissionAsync(Permissions.CAMERA)) {
const result = await ImagePicker.launchCameraAsync({
allowsEditing: true,
aspect: [4, 3],
})
if (!result.cancelled) {
onSend([{ image: result.uri }])
return result.uri
}
}
}
_takePhoto = async () => {
const status = await getPermission(Permissions.CAMERA);
if (status) {
const result = await ImagePicker.launchCameraAsync(options);
if (!result.cancelled) {
this.props.navigation.navigate("NewPost", { image: result.uri });
}
}
};