If I have a Blob object how can I get the URI (gs://...)?
The documentation says I can use self_link property to get the URI, but it returns the https URL instead (https://googleapis.com...) I am using python client library for cloud storage.
Thank you
To load data from a Cloud Storage data source, you must provide the Cloud Storage URI. The Cloud Storage URI comprises your bucket name and your object (filename). For example, if the Cloud Storage bucket is named mybucket and the data file is named myfile. csv , the bucket URI would be gs://mybucket/myfile.csv .
The name of the blob. This corresponds to the unique path of the object in the bucket. If bytes, will be converted to a unicode object. Blob / object names can contain any sequence of valid unicode characters, of length 1-1024 bytes when UTF-8 encoded.
Since you are not sharing with us how exactly are you trying to achieve this I did a quick script in Python to get this info
There is no specific method in blob to get the URI as gs://
in Python but you can try to script this by using the path_helper
def get_blob_URI():
"""Prints out a bucket's labels."""
# bucket_name = 'your-bucket-name'
storage_client = storage.Client()
bucket_name = 'YOUR_BUCKET'
blob_name = 'YOUR_OBJECT_NAME'
bucket = storage_client.get_bucket(bucket_name)
blob = bucket.blob(blob_name)
link = blob.path_helper(bucket_name, blob_name)
pprint.pprint('gs://' + link)
If you want to use the gsutil
tool you can also get all the gs://
Uris of a bucket using the command gsutil ls gs://bucket
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With