我在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并成功创建了该文件。 编辑: download.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。
提前致谢。
答案 0 :(得分:0)
根据文档字符串:
Args:
blob_key_or_info: BlobKey or BlobInfo record to serve.
content_type: Content-type to override when known.
save_as: If True, and BlobInfo record is provided, use BlobInfos
filename to save-as. If string is provided, use string as filename.
If None or False, do not send as attachment.
start: Start index of content-range to send.
end: End index of content-range to send. End index is inclusive.
use_range: Use provided content range from requests Range header.
Mutually exclusive to start and end.
尝试将代码更改为
class ServeHandler(blobstore_handlers.BlobstoreDownloadHandler):
def get(self):
blob_key = BlobKey(urllib.unquote(self.request.get('key')))
self.send_blob(blob_key, save_as=True)