Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
pickImage = async ({ onSend }) => {
const { t } = this.props;
if (await this.checkPermission(Permissions.CAMERA_ROLL, 'android')) {
const { cancelled, uri } = await ImagePicker.launchImageLibraryAsync(settings.chat.image.imagePicker);
if (!cancelled) {
const { size } = await FileSystem.getInfoAsync(uri);
const reg = /[^\\/]*\.\w+$/;
if (size <= settings.chat.image.maxSize && reg.test(uri)) {
const type = mime.lookup(uri);
const name = uri.match(reg)[0];
const imageData = new ReactNativeFile({ uri, type, name });
onSend({ attachment: imageData });
} else {
this.setState({ notify: t('attachment.errorMsg') });
}
}
} else {
this.setState({ notify: t('permission.errorMsg') });
}
};
}).then((file) => {
const avatar = new ReactNativeFile({
name: 'avatar',
type: file.mime,
size: file.size,
path: file.path,
uri: file.path,
});
self.setState({ avatar });
});
}
onPress = async () => {
const { status } = await Permissions.getAsync(Permissions.CAMERA_ROLL);
if (status !== "granted") {
await Permissions.askAsync(Permissions.CAMERA_ROLL);
}
const imageResult = await ImagePicker.launchImageLibraryAsync({});
if (!imageResult.cancelled) {
const file = new ReactNativeFile({
uri: imageResult.uri,
type: imageResult.type,
name: "picture"
});
const {
field: { name },
form: { setFieldValue }
} = this.props;
setFieldValue(name, file);
}
};
}).then((file) => {
const icon = new ReactNativeFile({
name: 'avatar',
type: file.mime,
size: file.size,
path: file.path,
uri: file.path,
});
self.setState({ icon });
});
}