【问题标题】:Blobs in BlobStore in GAEGAME 中的 Blob 存储中的 Blob
【发布时间】: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


【解决方案1】:

根据文档字符串:

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)

【讨论】:

    猜你喜欢
    • 2012-05-01
    • 2012-04-08
    • 2016-12-07
    • 2013-06-04
    • 2019-05-01
    • 2012-04-10
    • 2021-07-09
    • 1970-01-01
    • 2019-07-28
    相关资源
    最近更新 更多