Google Cloud Storage - Python Client - Get Link URL of a blob

Viewed 2721

The Link URL at the Object details in the GoogleCloudStorage browser follows the template:

https://storage.cloud.google.com/<project_name>/<file_name>?authuser=0&organizationId=<org_id>

I'm trying to get the exact same link using the python package google-cloud-storage. Diving into the blob properties I've found the followings (none of which are exactly what I need):

  • self_link: https://www.googleapis.com/storage/v1/b/<project_name>/o/<file_name>
  • media_link: https://storage.googleapis.com/download/storage/v1/b/<project_name>/o/<file_name>?generation=<gen_id>&alt=media

Note: If I replace storage.googleapis.com with storage.cloud.google.com at the media_link I get to download the file as I expect (getting asked for a valid Google Account with the required permissions).

Is there any way to get the link directly from the blob object?

2 Answers

Here the pattern:

https://storage.googleapis.com/<BUCJET_NAME>/path/to/file

For example, for a bucket my_bucket and a file stored in this path folder_save/2020-01-01/backup.zip, you have this url https://storage.googleapis.com/my_bucket/folder_save/2020-01-01/backup.zip

I think that the best approach is manually generate the URL that you need by replacing the domain of the URL.

In client library source I couldn’t find any reference to a method/property in the blob class that uses the domain “storage.cloud.google.com”

even using the public url property the result is the URL that points to googleapis

Related