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?
-
Are the objects public? If not, how do you want to do authorization? – jterrace Dec 09 '13 at 19:33
3 Answers
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

- 37,021
- 23
- 116
- 145
-
Is it better to use a public URL and link from a website, or use an authenticated service account to retrieve a file and stream it back to a web server to the end user? – user2966445 Sep 04 '19 at 04:02
-
Depends entirely on your needs. Allowing an end user to stream it directly saves bandwidth and, therefore, cost, but proxying it through your own system allows more control. – Brandon Yarbrough Sep 04 '19 at 06:49
-
Also note that the object name might include slashes (`/`), thus "simulating" an hierarchy (though there is no hierarchy inside a bucket, it is a flat namespace, but some tools might pretend that the hierarchy exist for better visualization. – Rafael Eyng Jan 08 '20 at 02:09
One way is to use https://storage.cloud.google.com// see more documentation at https://developers.google.com/storage/docs/collaboration#browser

- 4,489
- 4
- 21
- 25
If the file is not public, you can use this link to the file and it will authenticate with your signed in Google account:
https://storage.cloud.google.com/{bucket-name}/{folder/filename}
Otherwise generate a signed URL:
gsutil signurl -d 10m Desktop/private-key.json gs://example-bucket/cat.jpeg

- 6,412
- 3
- 39
- 48