【发布时间】:2018-07-19 11:02:18
【问题描述】:
我的困惑是为什么我需要包含“传统”云存储角色。我更喜欢避免说“遗留”的东西,因为听起来它们会在这些日子里被弃用。 我做错了吗?
这是我的情况:
我正在使用 appengine 项目中的服务帐户来访问另一个项目中云存储中的文件。我正在使用 Google Python 客户端访问数据。
我已分配角色:
Storage Object Creator
Storage Object Viewer
但是当我尝试访问文件时出现错误:
<service account> does not have storage.buckets.get access
只有在我添加“遗留角色”后,它才能最终获得访问权限:
Storage legacy bucket writer
Storage legacy bucket reader
代码如下:
def download_blob(bucket_name, source_blob_name, destination_file_name):
"""Downloads a blob from the bucket."""
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))
def upload_blob(bucket_name, source_file_name, destination_blob_name):
"""Uploads a file to the bucket."""
bucket = storage_client.get_bucket(bucket_name)
blob = bucket.blob(destination_blob_name)
blob.upload_from_filename(source_file_name)
print('File {} uploaded to {}.'.format(
source_file_name,
destination_blob_name))
谢谢 抢
【问题讨论】:
-
你好 Rob,你能提供你正在使用的代码吗?
-
@FrankNatividad 添加。
标签: google-app-engine google-cloud-storage