[Vuejs]-Download File With axios post method in vue js

3👍

Does it work when you specify responseType ?

  axios.post('/api/downloadFile',
  { 'file':item },
  { responseType: 'blob' })
  .then(res => {
    let blob = new Blob([res.data], { type: res.headers['content-type'] });
    let link = document.createElement('a');
    link.href = window.URL.createObjectURL(blob);
    link.download =item.slice(item.lastIndexOf('/')+1);
    link.click()
  }).catch(err => {})

Leave a comment