Download file with Vue.js and Python Flask Download file with Vue.js and Python Flask flask flask

Download file with Vue.js and Python Flask


OK I figured it out. I actually need to configure axios response type like this:

axios({        url: url        method: 'POST',        responseType: 'blob', // important}).then((res) => {})

I actually would prefer to use the default URL setting, but the following didn't work for me.

axios.post('download', {    responseType: 'blob',}).then((res) => {


I'm guessing you opened the file in byte mode, but when it's returned in the view function, Flask tries to decode it to a string, then encode back to bytes. That's why you get a bigger file.

try returning

flask.send_file("path/to/file.zip", mimetype="application/zip", as_attachment=True, attachment_filename="filenamefordownload.zip")