Get Download URL from file uploaded with Cloud Functions for Firebase

后端 未结 23 1811
春和景丽
春和景丽 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:53

    This works if you just need a public file with a simple URL. Note that this may overrule your Firebase storage rules.

    bucket.upload(file, function(err, file) {
        if (!err) {
          //Make the file public
          file.acl.add({
          entity: 'allUsers',
          role: gcs.acl.READER_ROLE
          }, function(err, aclObject) {
              if (!err) {
                  var URL = "https://storage.googleapis.com/[your bucket name]/" + file.id;
                  console.log(URL);
              } else {
                  console.log("Failed to set permissions: " + err);
              }
          });  
        } else {
            console.log("Upload failed: " + err);
        }
    });
    

提交回复
热议问题