你需要
Content-Disposition: attachment; filename=....为浏览器设置HTTP标头以使用正确的文件名。
你可以
send_file()通过设置
as_attachment=True参数来设置此标头。然后从传入的文件对象中获取文件名。使用
attachment_filename参数显式设置其他文件名:
return send_file(os.path.join(filepath, filename), as_attachment=True)
从flask.send_file文档中:
as_attachment
–设置为True是否要发送带有Content-Disposition: attachment
标题的文件。attachment_filename
–附件的文件名(如果与文件名不同)。
你可能想改用该flask.send_from_directory()
函数。该函数首先确保文件名存在(NotFound
如果不存在,则引发),并确保文件名不包含任何..可能用于“转义”目录的相对元素。将此文件用于所有来自不受信任来源的文件名:
return send_from_directory(filepath, filename, as_attachment=True)



