I'm building an websites that allows the user to download files from my server. I wrote a route for serving the file:
@api.route('/download_results/<path:filename>')
def download_results(filename):
return send_from_directory(app.config['UPLOAD_FOLDER'], filename, as_attachment=True)
if i try to use an html tag like this:
<a class="btn btn-primary" herf="http://localhost/api/download_results/1234567890/results.zip" download="results.zip">Download results</a>
it doesn't work. but if i add an event listener in jQuery:
$('a').on('click', function(event) {
event.preventDefault();
window.location.href = location.origin + '/api/download_results/' + data.parsedData[0];
});
it works and i can download but i get a warning:
Resource interpreted as Document but transferred with MIME type application/x-zip-compressed: " http://localhost/api/download_results/1234567890/results.zip ".
Anyone knows what i'm doing wrong and how i can solve this? Thanks!
您在锚标记的href
属性中有错字。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.