【发布时间】:2013-05-15 10:25:37
【问题描述】:
我正在使用 REST api 从 appengine 将文件写入 Google 存储。
我的代码如下所示:
url = 'http://storage.googleapis.com/' + bucketName + filePath
LOG.debug('Attempting to write file: ' + url)
'''
compute expiry time one year in the future
'''
expiresDate = datetime.utcnow() + timedelta(days=zconfig.CACHE_EXPDAY)
formatStr = '%a, %d %b %Y %H:%M:%S GMT'
start_cloud = time.time()
headers = {'Content-Type' : mime,
'Content-Length' : len(imageBytes),
'Cache-Control' : 'Expires=' + expiresDate.strftime(formatStr),
'x-goog-api-version' : '2',
'x-goog-acl' : 'public-read'}
resp, content = http.request(url, 'PUT', body=imageBytes, headers=headers)
根据 google storage api docs,REST api 采用“x-goog-acl”标头,可以更改对象上的 ACL。
但是,在创建此对象后,ACL 仍未设置为 public-read。我可以从 gsutil 以及 GS 浏览器中看到这一点。
谁能告诉我我做错了什么?
编辑:jterrace 指出我没有将标头传递给请求。我修好了。但它仍然没有在对象上设置公共读取 ACL。
【问题讨论】:
-
您是否忘记将 headers 字典传递给请求函数?
标签: google-app-engine google-cloud-storage