Skip to content

Instantly share code, notes, and snippets.

@godswillokokon
Last active May 11, 2020 12:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save godswillokokon/0411463d58f4d3d2958710f37dec0ff1 to your computer and use it in GitHub Desktop.
Save godswillokokon/0411463d58f4d3d2958710f37dec0ff1 to your computer and use it in GitHub Desktop.
...
const selectPhotoTapped = () => {
const options = {
title: 'Select Photo',
storageOptions: {
skipBackup: true,
path: 'images',
},
};
ImagePicker.showImagePicker(options, (response) => {
// console.log('Response = ', response);
if (response.didCancel) {
console.log('User cancelled image picker');
} else if (response.error) {
console.log('ImagePicker Error: ', response.error);
} else {
const uri = response.uri;
const type = response.type;
const name = response.fileName;
const source = {
uri,
type,
name,
}
cloudinaryUpload(source)
}
});
}
const cloudinaryUpload = (photo) => {
const data = new FormData()
data.append('file', photo)
data.append('upload_preset', 'ogcodes')
data.append("cloud_name", "ogcodes")
fetch("https://api.cloudinary.com/v1_1/ogcodes/upload", {
method: "post",
body: data
}).then(res => res.json()).
then(data => {
setPhoto(data.secure_url)
}).catch(err => {
Alert.alert("An Error Occured While Uploading")
})
}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment