2013-05-09 62 views
1

我想服務使用Flask保存在blobstore中的大文件。從燒瓶中的GAE blobstore服務blob

對於較小的文件,我可以簡單地做:

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 

,但它失敗了較大的文件。如何將BlobstoreDownloadHandler併入我的Flask應用程序而無需訴諸webapp2?

回答

2

如果您不關心範圍請求,那麼您可以使用blob-key的字符串版本設置'X-AppEngine-BlobKey'的頭部(或blobstore.BLOB_KEY_HEADER以確保安全)以及您擁有的內容類型和配置。