-
-
Save godswillokokon/0411463d58f4d3d2958710f37dec0ff1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
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