Python GAE的BlobStore中的Blobs
我在GAE BlobStore中创建了Blob,这些文件创建成功,问题是当我尝试使用BlobKey为这些文件提供服务时,我得到的内容长度为0,如下所示:Python GAE的BlobStore中的Blobs,python,google-app-engine,blobstore,Python,Google App Engine,Blobstore,我在GAE BlobStore中创建了Blob,这些文件创建成功,问题是当我尝试使用BlobKey为这些文件提供服务时,我得到的内容长度为0,如下所示: Status: 200 OK Cache-Control: no-cache X-AppEngine-BlobKey: crXwVb6vKoS8OykvgPmSew== Content-Type: application/zip Content-Disposition: attachment; filename="test.zip" Expir
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.zipis成为在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那里得到一个斑点
提前感谢。根据文档字符串:
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)
根据文档字符串:
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)
@彼得·克内戈:好的,我会编辑这个问题。你从哪里弄来的布布基?看起来它是Base64编码的。@Peter Knego:首先我在BlobStore中创建了zip存档文件,然后获取该文件的密钥并通过URL将其传递到download.py,然后在此页面中获取密钥并尝试获取blob。尝试不使用content\u type参数,而使用save\u as=True@Peter克内戈:谢谢你的帮助,问题是我试图在处理程序中打印blob_键,我删除了这条语句,它成功了。//内容类型并按需要保存them@Peter克内戈:好的,我会编辑这个问题。你从哪里弄来的布卢基?看起来它是Base64编码的。@Peter Knego:首先我在BlobStore中创建了zip存档文件,然后获取该文件的密钥并通过URL将其传递到download.py,然后在此页面中获取密钥并尝试获取blob。尝试不使用content\u type参数,而使用save\u as=True@Peter克内戈:谢谢你的帮助,问题是我试图在处理程序中打印blob_键,我删除了这条语句,它成功了。//内容类型并按需要保存