Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_pickImageAsync = async () => {
const { status } = await Permissions.askAsync(Permissions.CAMERA_ROLL);
if (status !== 'granted') {
this.setState({
errorMessage: 'Permission to access photos was denied',
});
return null;
}
const result = await ImagePicker.launchImageLibraryAsync({
allowsEditing: true,
aspect: [4, 3],
});
console.log(result);
if (!result.cancelled) {
const storageUrl = await Fire.shared.uploadImageAsync(result.uri);
console.log('local', result.uri, 'global', storageUrl);
return storageUrl;
}
// Maybe do something
return null;
};
getAvatarPhoto = async () => {
// expo version
try {
let result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: 'Images',
base64: true,
});
if (!result.cancelled) {
this.setState({ avatarUri: result.uri });
}
} catch (err) {
console.warn(err);
}
// for full documentation on the Image Picker api
// see https://github.com/react-community/react-native-image-picker
// const options = {
// title: 'Select Avatar',
const takePhoto = option === 0;
const permission = takePhoto ? Permissions.CAMERA : Permissions.CAMERA_ROLL;
// Do we have permission?
let permissions = await Permissions.getAsync( permission );
if ( permissions.status !== 'granted' ) {
// Asking for permission...
permissions = await Permissions.askAsync( permission );
if ( permissions.status !== 'granted' ) {
// No permission :(
return;
}
}
const response = await (
takePhoto ? ImagePicker.launchCameraAsync( cameraOptions ) : ImagePicker.launchImageLibraryAsync( libraryOptions )
);
if ( response.cancelled ) {
return;
}
// You can display the image using either data:
// dispatch(createPost('attachment'));
// api
// .upload('/wp/v2/media', response.data, 'image/png', 'test.png')
// .then(data => {
// dispatch({
// type: 'TYPE_POSTS_NEW_UPDATED',
// payload: {
// type: 'attachment',
async () => {
const result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions.Videos
});
if (!result.cancelled) {
result.uri;
result.width;
result.height;
}
};
_pickImageFromLibrary = async () => {
const status = await this._verifyPermissions();
let result = await ImagePicker.launchImageLibraryAsync({
allowsEditing: true,
aspect: [4, 3],
});
if (result.cancelled) {
console.log("Cancelled")
} else {
this._processImage(result);
}
};
pickImage = async () => {
let result = await ImagePicker.launchImageLibraryAsync({
allowsEditing: true
});
console.log(result);
if (!result.cancelled) {
this.setState({ image: result.uri });
}
};
text: 'Upload a picture', onPress: async () => {
const { status } = await Permissions.askAsync(Permissions.CAMERA_ROLL);
if (status === 'granted') {
const result = await ImagePicker.launchImageLibraryAsync()
if (!result.cancelled) this.uploadFile(result);
}
}
}, {
export const fromLibrary = async () => {
const hasit = await getPermission(Permissions.CAMERA_ROLL);
if (!hasit) return;
const { cancelled, uri } = await ImagePicker.launchImageLibraryAsync({
allowsEditing: false,
aspect: [1, 1],
quality: 0.85,
base64: false,
exif: true,
});
if (cancelled) {
return;
}
const { uri: reducedUri } = await reduceImageAsync(uri);
return reducedUri;
};
export const fromCamera = async () => {
Permissions.askAsync(Permissions.CAMERA_ROLL).then((isAllowed) => {
if (!isAllowed) return;
ImagePicker.launchImageLibraryAsync({})
.then((result) => {
if (!result.cancelled) {
this.setState({
file: result,
status: "file selected"
});
}
});
});
}
_pickImage = async () => {
if (!(await this.permissionGuard())) return;
let result = await ImagePicker.launchImageLibraryAsync({
base64: true,
quality: 0.25,
});
if (!result.cancelled) {
this._setImage(result);
}
};