python - download_to_filename 创建一个空文件(谷歌云存储)

标签 python google-cloud-platform google-cloud-storage

回答: 我需要授予对存储策略的所有权访问权限,而不仅仅是向连接到我的实例的 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/

相关文章:

google-app-engine - GAE 应用程序可以在没有 OAuth 舞蹈的情况下访问 Cloud Storage RESTful API 吗?

google-cloud-storage - 如何在多个帐户中使用 gsutil?

node.js - 如何根据正则表达式从Google Cloud Storage存储桶中获取文件?

python - 为什么不替换新数据框中的列?

python - 使用 NumPy 将向量保存到 Python 文件中

python - 解决排列和约束问题

php - 为 Google Compute Engine 托管的 Wordpress 激活邮件的最佳方式?

python - 如何在 Python 中使用 Apache Beam 读取和操作 Json 文件

python - Django exists() 与 DoesNotExist

git - cloudbuild.yaml 包含不同的云构建器配置