Get Download URL from file uploaded with Cloud Functions for Firebase

后端 未结 23 2209
春和景丽
春和景丽 2020-11-22 01:19

After uploading a file in Firebase Storage with Functions for Firebase, I\'d like to get the download url of the file.

I have this :

...

return buck         


        
23条回答
  •  一个人的身影
    2020-11-22 01:48

    For those who are using Firebase SDK andadmin.initializeApp:

    1 - Generate a Private Key and place in /functions folder.

    2 - Configure your code as follows:

    const serviceAccount = require('../../serviceAccountKey.json');
    try { admin.initializeApp(Object.assign(functions.config().firebase, { credential: admin.credential.cert(serviceAccount) })); } catch (e) {}
    

    Documentation

    The try/catch is because I'm using a index.js that imports other files and creates one function to each file. If you're using a single index.js file with all functions, you should be ok with admin.initializeApp(Object.assign(functions.config().firebase, { credential: admin.credential.cert(serviceAccount) }));.

提交回复
热议问题