Get Download URL from file uploaded with Cloud Functions for Firebase

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

    If you use the predefined access control lists value of 'publicRead', you can upload the file and access it with a very simple url structure:

    // Upload to GCS
    const opts: UploadOptions = {
      gzip: true,
      destination: dest, // 'someFolder/image.jpg'
      predefinedAcl: 'publicRead',
      public: true
    };
    return bucket.upload(imagePath, opts);
    

    You can then construct the url like so:

    const storageRoot = 'https://storage.googleapis.com/';
    const bucketName = 'myapp.appspot.com/'; // CHANGE TO YOUR BUCKET NAME
    const downloadUrl = storageRoot + bucketName + encodeURIComponent(dest);
    

提交回复
热议问题