如何通过给python脚本提供文件路径并下载处理过的文件来处理上传的文件? 代码
@app.route("/upload", methods=['POST'])
def upload():
target = os.path.join(APP__ROOT, 'data/')
print(target)
if not os.path.isdir(target):
os.mkdir(target)
for file in request.files.getlist("file"):
filename = file.filename
print(filename)
destination = "/".join([target, filename])
print(destination)
file.save(destination)
return render_template("downloads.html")
您需要返回该文件。
response = app.make_response(file)
response.headers["Content-Disposition"] = "attachment; filename=yourfile.csv"
return response