How do you get or generate a URL to the object in a bucket?

adam-singer picture adam-singer · Dec 9, 2013 · Viewed 22.1k times · Source

I'm storing objects in buckets on google cloud storage. I would like to provide a http url to the object for download. Is there a standard convention or way to expose files stored in cloud storage as http urls?

Answer

Brandon Yarbrough picture Brandon Yarbrough · Dec 9, 2013

Yes. Assuming that the objects are publicly accessible:

http://BUCKET_NAME.storage.googleapis.com/OBJECT_NAME

You can also use:

http://storage.googleapis.com/BUCKET_NAME/OBJECT_NAME

Both HTTP and HTTPS work fine. Note that the object must be readable by anonymous users, or else the download will fail. More documentation is available at https://developers.google.com/storage/docs/reference-uris

If it is the case that the objects are NOT publicly accessible and you only want the one user to be able to access them, you can generate a signed URL that will allow only the holder of the URL to download the object, and even then only for a limited period of time. I recommend using one of the GCS client libraries for this, as it's easy to get the signing code slightly wrong: https://developers.google.com/storage/docs/accesscontrol#Signed-URLs