【发布时间】:2023-03-04 16:07:01
【问题描述】:
我有一个客户端页面,它将列出容器中的所有文件,在选择文件时,文件名和容器名称将发送到服务器。 服务器应启动文件下载并发送文件作为对客户端请求的响应,请参考下图:
我试过 get_blob_to_stream
@app.route("/blobs/testDownload/")
def testDownload():
container_name =request.args.get("containerName")
print(container_name)
local_file_name= request.args.get("fileName")
with BytesIO() as input_blob:
with BytesIO() as output_blob:
# Download as a stream
block_blob_service.get_blob_to_stream(container_name, local_file_name, input_blob)
copyfileobj(input_blob, output_blob)
newFile = str(output_blob.getvalue())
with open("file.txt","a") as f:
f.write(newFile)
f.close()
return send_file('file.txt',attachment_filename='sample.txt',as_attachment=True,mimetype='text/plain')
但是正在下载的文件只有文本文件格式,我想下载文件而不管它的格式。我知道这不是通过 Web API 下载文件的正确方法。
【问题讨论】:
标签: python azure download blob