gpt4 book ai didi

javascript - 用于下载文件的flask html链接

转载 作者:行者123 更新时间:2023-12-01 02:04:09 25 4
gpt4 key购买 nike

我正在构建一个网站,允许用户从我的服务器下载文件。我写了一条服务文件的路线:

@api.route('/download_results/<path:filename>')
def download_results(filename):
return send_from_directory(app.config['UPLOAD_FOLDER'], filename, as_attachment=True)

如果我尝试使用这样的 html 标签:

<a class="btn btn-primary" herf="http://localhost/api/download_results/1234567890/results.zip" download="results.zip">Download results</a>

这不起作用。但如果我在 jQuery 中添加一个事件监听器:

$('a').on('click', function(event) {
event.preventDefault();
window.location.href = location.origin + '/api/download_results/' + data.parsedData[0];
});

它可以工作,我可以下载,但我收到警告:

Resource interpreted as Document but transferred with MIME type application/x-zip-compressed: "http://localhost/api/download_results/1234567890/results.zip".

有人知道我做错了什么以及如何解决这个问题吗?谢谢!

最佳答案

您的 anchor 标记的 href 属性有拼写错误。

关于javascript - 用于下载文件的flask html链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50255366/

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