如何解决如何接收来自flask发送的flask文件?
问题是我使用send_file函数将文件从另一个烧瓶应用程序发送到了烧瓶应用程序(在我的情况下,该文件是zip文件)。
@app.route('/return_file')
def return_file():
if request.method == 'GET':
if request.headers["Get-Data"] == "zip":
return send_file(os.path.abspath(os.path.join(zip_path,zip_name)),as_attachment=True)
另一个服务器,它也是一个烧瓶应用程序,将这样的请求发送到文件服务器
requests.get(host_server+'/return_file',headers={"Get-Data" : "zip"})
并收到这样的回复。 有一些内容是22个字节,但不是我发送的文件。 当我通过浏览器应用(基于Vue.js)收到此类回复时,它会成功下载文件(例如Chrome)。
我在做什么错,以及如何使用flask正确接收文件?
解决方法
这是正确的方法。 检查您发送的文件是否为空。
您可以这样保存它。
with open ("some.zip","wb+") as file:
file.write (requests.get(host_server+'/return_file',headers={"Get-Data" : "zip"}).content)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。