Search code examples
google-cloud-storagegoogle-compute-engine

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


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?


Solution

  • 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