Skip to content

Instantly share code, notes, and snippets.

@alejovdev
Last active January 22, 2020 19:25
Show Gist options
  • Save alejovdev/6ab6d2be61520fe101a76cfccaed612f to your computer and use it in GitHub Desktop.
Save alejovdev/6ab6d2be61520fe101a76cfccaed612f to your computer and use it in GitHub Desktop.
const pickImage = async () => {
let result = await ImagePicker.launchCameraAsync({
mediaTypes: ImagePicker.MediaTypeOptions.Images,
allowsEditing: true,
aspect: [1, 1],
quality: 1,
base64: true
})
if (!result.cancelled){
// I'm adding the data:image, if you want to use the image locally before uploading, you can use a state hook first
uploadImage('data:image/png;base64,' + result.base64)
}
}
const uploadImage = async data_url => {
let upload = functions.httpsCallable('uploadExpoImage')
let res = await upload({
data_url: data_url,
path: `alejov/images` //Replace with the location where you want your image
})
if (typeof res.data === 'string') url = res.data
// Now you have url that is whatever you returned from uploadExpoImage
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment