Skip to content

Instantly share code, notes, and snippets.

@alejovdev
Last active January 22, 2020 19:15
Show Gist options
  • Save alejovdev/50f054dd88f93e30df8c8ed66bac3f9c to your computer and use it in GitHub Desktop.
Save alejovdev/50f054dd88f93e30df8c8ed66bac3f9c to your computer and use it in GitHub Desktop.
exports.uploadExpoImage = functions.https.onCall(
async ({ data_url, path }, context) => {
try {
let base64EncodedImageString = `${data_url}`.replace(
'data:image/png;base64,',
''
)
let mimeType = 'image/png'
let imageBuffer = new Buffer(base64EncodedImageString, 'base64')
let bucket = admin.storage().bucket()
let file = bucket.file(path)
await file.save(imageBuffer, {
metadata: { contentType: mimeType }
})
let url =
'https://firebasestorage.googleapis.com/v0/b/appid.appspot.com/o/'
url += path.replace(/\//g, '%2F')
url += '?alt=media'
return url
} catch (e) {
return null
}
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment