[英]flask html link for downloading file
我正在建立一个网站,允许用户从我的服务器下载文件。 我写了一条送达文件的路线:
@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];
});
它可以工作,我可以下载,但是我得到警告:
资源被解释为文档,但以MIME类型application / x-zip-compressed传输:“ http://localhost/api/download_results/1234567890/results.zip ”。
谁知道我在做什么错,我该如何解决? 谢谢!
您在锚标记的href
属性中有错字。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.