[Vuejs]-Vue client file direct download from node js server doesnt work

1👍

Alright, seems like a complex subject, but I found my solution tho here you go:

      this.$axios({
          method: 'GET',
          url: // ur backend api url,
          responseType: 'arraybuffer'
        })
        .then(response => {
          var blob = new Blob([response.data], {type: response.headers['content-type']})
          var link = document.createElement('a')
          link.href = window.URL.createObjectURL(blob)
          link.download = // name the downloaded file
          link.click()
        })
        .catch(error => { 
          // whatever
        })
        .finally(() => {
          // whatever
        }

0👍

You need to change the responseType in axios…

axios({
    method: 'GET',
    url: process.env.VUE_APP_AUDIO_API_URL + '/api/tracks/download/' + this.fileId,
    responseType: 'arraybuffer'
}).then(response => {
   console.log(response.data)
}).catch(error => {
   console.error(error)
})

Leave a comment