问题描述
我正在使用一个库 (Apache libcloud) 向谷歌存储发出请求。
在库内部,向在谷歌存储中查询的 URL 发出 HEAD 请求。
您可以找到它的代码 here,搜索 def get_object
。
重要的一行是
response = self.connection.request(object_path,method='HEAD')
根据 Google Documentation of HEAD response objects,content-length
字段应该是响应的一部分:
Response
...
expires: Wed,30 May 2018 21:41:23 GMT
date: Wed,30 May 2018 21:41:23 GMT
cache-control: private,max-age=0
last-modified: Wed,30 May 2018 20:36:34 GMT
etag: "2218880ef78838266ecd7d4c1b742a0e"
x-goog-generation: 1486161811706000
x-goog-Metageneration: 15
x-goog-stored-content-encoding: identity
x-goog-stored-content-length: 328
content-type: image/jpg
x-goog-hash: crc32c=HBrbzQ==
x-goog-hash: md5=OCydg52+pPG1Bwawjsl7DA==
x-goog-storage-class: STANDARD
accept-ranges: bytes
content-length: 328 # <--- here
...
但是,某些文件(但并非所有文件)缺少它。
在这两种情况下,我都收到了 x-goog-stored-content-length
条目,但图书馆需要 content-length
。
content-length
标头在 def _headers_to_object
中的调用链下游使用了一点,由于缺少标头,我在那里得到了 KeyError:
def _headers_to_object(self,object_name,container,headers):
hash = headers['etag'].replace('"','')
extra = {'content_type': headers['content-type'],'etag': headers['etag']}
Meta_data = {}
if 'last-modified' in headers:
extra['last_modified'] = headers['last-modified']
for key,value in headers.items():
if not key.lower().startswith(self.http_vendor_prefix + '-Meta-'):
continue
key = key.replace(self.http_vendor_prefix + '-Meta-','')
Meta_data[key] = value
obj = Object(name=object_name,size=headers['content-length'],# <-- here
hash=hash,extra=extra,Meta_data=Meta_data,container=container,driver=self)
return obj
问题是: 当我上传文件导致谷歌存储不发送该标头时,我可能对文件做了什么? 或者这是谷歌存储中的错误(我怀疑)?
更多信息:
- 内容类型为
application/json
- 此文件采用 gzip 编码。
- 它适用于其他 gzip 编码文件
- 我使用的是 Apache libcloud API 3.3.0
- 我不认为这是 libcloud 中的错误,因为 HEAD 的文档指定了
content-length
标头,但如果我覆盖_headers_to_object
以使用x-goog-stored-content-length
,它会起作用。 - 我无法使用我目前可以公开演示的文件来重现这一点
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)