回答: 我需要授予对存储策略的所有权访问权限,而不仅仅是向连接到我的实例的 IAM 授予一般 API 所有权。
我只是按照网站上的教程操作:https://cloud.google.com/storage/docs/downloading-objects#storage-download-object-python
说的是
def download_blob(bucket_name, source_blob_name, destination_file_name):
"""Downloads a blob from the bucket."""
storage_client = storage.Client()
bucket = storage_client.get_bucket(bucket_name)
blob = bucket.blob(source_blob_name)
blob.download_to_filename(destination_file_name)
print('Blob {} downloaded to {}.'.format(
source_blob_name,
destination_file_name))
download_blob([BUCKETNAME],[FILENAME],"/home/me/documents/file.png")
我没有收到错误,但要执行的最后一行是 blob.download_to_filename(destination_file_name)
这会创建一个空文件。
附加信息: 我的桶的格式是“mybucketname” 我的文件格式为“sdg-1234-fggr-34234.png”
我希望任何人都了解我的问题。 是编码吗?或者 download_to_filename 不执行?还是别的?
最佳答案
使用 API 时,重要的是授予对存储策略的所有权访问权限,而不仅仅是将一般 API 所有权授予连接到实例的 IAM。
关于python - download_to_filename 创建一个空文件(谷歌云存储),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49634307/