Last active
January 22, 2020 19:15
-
-
Save alejovdev/50f054dd88f93e30df8c8ed66bac3f9c 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
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