我希望 Backblaze 上的私有存储桶中的一些文件(在这种情况下为图像)由 Flask 中的 API 端点公开。我不确定如何处理DownloadedFile
从返回的对象bucket.download_file_by_name
@app.route('/b2-image/<filename>', methods=('GET',))
def b2_image(filename):
info = InMemoryAccountInfo()
b2_api = B2Api(info)
app_key_id = env['MY_KEY_ID']
app_key = env['MY_KEY']
b2_api.authorize_account('production', app_key_id, app_key)
bucket = b2_api.get_bucket_by_name(env['MY_BUCKET'])
file = bucket.download_file_by_name(filename)
bytes = BytesIO()
#something sort of like this???
#return Response(bytes.read(file), mimetype='image/jpeg')
bucket.download_file_by_name
返回一个DownloadedFile
对象,我不知道如何处理它。该文档没有提供任何示例,似乎建议我应该执行以下操作:
file = bucket.download_file_by_name(filename)
#this obviously doesn't make any sense
image_file = file.save(file, file)