Generate Download URL After Successful Upload

前端 未结 2 670
醉梦人生
醉梦人生 2021-01-14 20:35

I have successfully uploaded files to Firebase\'s storage via Google Cloud Storage through JS! What I noticed is that unlike files uploaded directly, the files uploaded thro

2条回答
  •  醉梦人生
    2021-01-14 21:11

    When using the GCloud client, you want to use getSignedUrl() to download the file, like so:

    bucket.file('photos/' + filename).getSignedUrl({
      action: 'read',
      expires: '03-17-2025'
    }, function(err, url) {
      if (err) {
        console.error(err);
        return;
      }
    
      // The file is now available to read from this URL.
      request(url, function(err, resp) {
        // resp.statusCode = 200
      });
    });
    

提交回复
热议问题