How to get the URL to a Google Cloud Storage file using gcloud-node?

7.3k Views Asked by At

Using the gcloud Node library, how do I get the URL for a file within a Cloud Storage bucket?

Consider the following instantation of a file object:

let bucket = gcs.bucket(`aBucket`)
let cloudFile = bucket.file(`aFile`)

I would like to get the URL for downloading cloudFile.

2

There are 2 best solutions below

2
On BEST ANSWER

You can use a variety of request URIs, including storage.googleapis.com/<bucket>/<object>.

0
On

If file is public, then you can use a corresponding method:

cloudFile.publicUrl()