serving blobs from GAE blobstore in flask

2019-02-20 10:49发布

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?

1条回答
Summer. ? 凉城
2楼-- · 2019-02-20 11:38

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.

查看更多
登录 后发表回答