【发布时间】:2012-03-31 08:56:43
【问题描述】:
我在 GAE BlobStore 中创建了 blob,并且这些文件创建成功,问题是当我尝试使用 BlobKey 提供这些文件时,我得到了 content-length=0,如下所示:
Status: 200 OK
Cache-Control: no-cache
X-AppEngine-BlobKey: crXwVb6vKoS8OykvgPmSew==
Content-Type: application/zip
Content-Disposition: attachment; filename="test.zip"
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Content-Length: 0
这样 (test.zip) 是在 BlobStore 中创建的文件,我在管理控制台中检查了 BlobStore,并且该文件已成功创建。 编辑: 下载.py代码:
def mime_type(filename):
return guess_type(filename)[0]
class ServeHandler(blobstore_handlers.BlobstoreDownloadHandler):
def get(self):
blob_key = self.request.get('key')
blob_key = str(urllib.unquote(blob_key))
blob_info = blobstore.BlobInfo.get(blob_key)
content_type1 =mime_type(blob_info.filename)
save_as1 = blob_info.filename
self.send_blob(blob_key,content_type=content_type1,save_as=save_as1)
def main():
application = webapp.WSGIApplication([
(r'/download.*', ServeHandler),
], debug=True)
run_wsgi_app(application)
if __name__ == '__main__':
main()
密钥存在于 URL 中:
http://localhost:8080/download.py?key=Es9f00P29wNTZoeL9ccS4g==
我得到它来从 blobstore 获取 blob。
提前致谢。
【问题讨论】:
-
@Peter Knego:好的,我会编辑问题。
-
你从哪里得到 blobkey?看起来是 Base64 编码的。
-
@Peter Knego:首先我在 BlobStore 中创建 zip 存档文件,然后获取该文件的密钥并通过 URL 将其传递到 download.py,然后在此页面中我获取密钥并尝试获取斑点。
-
尝试不使用
content_type参数并使用save_as=True -
@Peter Knego:感谢您的帮助,问题是我试图在处理程序中打印 blob_key,我删除了此语句并且它有效。//内容类型并保存为我需要它们
标签: python google-app-engine blobstore