gpt4 book ai didi

google-cloud-platform - 如何在谷歌云存储 (Python) 中获取 blob 的 URI

转载 作者:行者123 更新时间:2023-12-03 23:47:44 28 4
gpt4 key购买 nike

如果我有一个 Blob 对象,我如何获得 URI (gs://...)?

文档说我可以使用 self_link 属性来获取 URI,但它返回 https URL( https://googleapis.com.. 。)
我正在使用 python 客户端库进行云存储。

谢谢

最佳答案

由于您没有与我们分享您究竟是如何实现这一目标的,我在 Python 中做了一个快速脚本获取此信息

blob 中没有特定的方法来获取 URI 为 gs://在 Python 中,但您可以尝试使用 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)

如果您想使用 gsutil工具您还可以获得所有 gs://使用命令 gsutil ls gs://bucket 的存储桶的 URI

关于google-cloud-platform - 如何在谷歌云存储 (Python) 中获取 blob 的 URI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61533453/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com