Download response from backend


#1

vuejs

         axios.post('/test',{},{headers: {'Content-Type': 'arraybuffer' }}).then(response=>{
         let blob = new Blob([response.data],{ type:'application/pdf'});
        let link = document.createElement('a');
        link.href = window.URL.createObjectURL(blob);
        link.download = "next1234.pdf";
         link.click();

backend for it

 res.sendFile(__dirname +'/x.pdf')

it get downloaded but not working file showing damaged
it works fine for postman.

any one help me please?


#2

Please don’t ping members in your post initially like this, hoping to get an immediate response like this. This is poor and rude forum etiquette. If Linus knows and can, he will on his own accord.


#3

ok. I removed it.


#4

any solution with this problem?


#5

The Content-Type seems invalid. Try:
{
responseType: ‘arraybuffer’,
headers: {
‘Accept’: ‘application/octet-stream’,
},
}