本文介绍了在烧瓶中从GAE Blobstore服务斑点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Flask来保存在blobstore中保存的大文件。



对于较小的文件,我可以简单地做:

  def download_blob blob_key):
blob_info = blobstore.get(blob_key)
response = make_response(blob_info.open()。read())
response.headers ['Content-Type'] = blob_info。 content_type
response.headers ['Content-Disposition'] ='attachment; filename =%s'%blob_info.filename

返回响应

但是对于较大的文件则失败。如何将BlobstoreDownloadHandler并入到我的Flask应用程序中,而不需要回到webapp2?

解决方案

如果您不关心范围请求,那么您可以使用blob-key的字符串版本以及内容类型和处理方式设置X-AppEngine-BlobKey(或blobstore.BLOB_KEY_HEADER)的标题。 p>

I'm trying to serve big files saved in the blobstore using Flask.

For smaller files I can simply do:

def download_blob(blob_key):
    blob_info = blobstore.get(blob_key)
    response = make_response(blob_info.open().read())
    response.headers['Content-Type'] = blob_info.content_type
    response.headers['Content-Disposition'] = 'attachment; filename="%s"' % blob_info.filename

    return response

but it fails for larger files. How can I incorporate BlobstoreDownloadHandler into my Flask app without resorting back to webapp2?

解决方案

If you don't care about range-requests, then you can just set a header of 'X-AppEngine-BlobKey' (or blobstore.BLOB_KEY_HEADER to be safe) with the string-version of your blob-key, along with the content type and disposition as you have it.

这篇关于在烧瓶中从GAE Blobstore服务斑点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 11:57