gpt4 book ai didi

javascript - 使用响应包 : Failed to load resource: Frame load interrupted 在 Safari 上下载文件

转载 作者:行者123 更新时间:2023-11-28 04:43:38 27 4
gpt4 key购买 nike

我想在用户单击按钮时下载文件。我是通过python Flask实现的,响应包如下

bib_text = 'test'

filename = 'test_file'
response = make_response(bib_text)
response.headers["Content-Disposition"] = "attachment; filename=%s.bib" % filename
return response

上面的代码在 Chrome 上运行良好,但在 Safari 上,javascript 控制台告诉我错误

Failed to load resource: Frame load interrupted

它下载的是 .bib.html 文件而不是 .bib 文件?知道发生了什么事吗?是否有另一种适用于 Safari 和 Chrome 的方法?

最佳答案

可以通过添加以下 header 规范来解决该问题

response.headers["Cache-Control"] = "must-revalidate"
response.headers["Pragma"] = "must-revalidate"
response.headers["Content-type"] = "application/bib"

内容类型规范是重要的

关于javascript - 使用响应包 : Failed to load resource: Frame load interrupted 在 Safari 上下载文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43575227/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com