flask+gunicorn中文文件下载

it2022-05-05  179

from flask import send_file from flask import make_response,send_from_directory,current_app import os from urllib.parse import quote @app.route('/download',methods=['GET','POST']) def download(): UPLOAD_FOLDER = '' #路径 ROOT_FOLDER = os.path.join(os.getcwd(), UPLOAD_FOLDER) # 整合绝对路径 filename='' #文件名 response = make_response(send_file(ROOT_FOLDER + filename)) # response.headers["Content-Disposition"] = "attachment; filename={}".format(filename.encode().decode('latin-1')) #用这个本地没问题gunicorn会报错 #修改 response.headers["Content-Disposition"] = "attachment; filename={}".format(quote(filename)) return response

最新回复(0)