How to write a Firebase http function that returns an url (in plain text) where an image can be downloaded?
I am using the latest version of Firebase Admin SDK.
I have a file called images/thumbnail.png
in the default bucket for which I would like to return the URL via a HTTP call, I came up with this code:
exports.getImageUrl = functions.https.onRequest((request, response) => {
return firebase.storage().bucket().file("images/thumbnail.png").getSignedUrl({
action: 'read',
expires: '03-09-2491'
})
.then(signedUrls => {
return response.send(signedUrls[0])
})
.catch(error => {
return response.status(500).send(error)
})
})
but this fails with :
callback is not a function
at /user_code/node_modules/firebase-admin/node_modules/@google-cloud/storage/src/file.js:1784:7
at Request._callback (/user_code/node_modules/firebase-admin/node_modules/google-auto-auth/index.js:362:9)
What am I doing wrong?
EDIT
I added logging in detail like this:
exports.getImage = functions.https.onRequest((request, response) => {
console.log("start")
const storage = firebase.storage()
console.log(storage)
const bucket = storage.bucket()
console.log(bucket)
const file = bucket.file("buildInExercises/bb_4zigzagcushionblue_thumbnail.png")
console.log(file)
return file.getSignedUrl({
action: 'read',
expires: '03-09-2491'
})
.then(urls => {
return response.send(urls)
})
.catch(error => {
return response.status(500).send(error)
})
})
I am now getting a proper reply:
{
"message": "Permission iam.serviceAccounts.signBlob is required to perform this operation on service account projects/snookercoachapp-dev/serviceAccounts/[email protected]."
}
It seams I have a permission issue?