Hello, I have a VUEJS 3 front-end and Laravel 8 back-end. I will download the pdf saved in public/pdf/temp/file.pdf
Now I make a call from VUEJS:
axios.post('/api/'+ this.url_access +'/rebuild', formData, { headers: { 'Content-Type': 'multipart/form-data', 'responseType': 'blob' }}) .then(response=>{ if(response.status == 200){ const url = window.URL.createObjectURL(new Blob([response.data])); const link = document.createElement('a'); link.href = url; link.setAttribute('download', 'test.pdf'); document.body.appendChild(link); link.click(); } }) .catch(error=>{ console.log(error); })
In the backend I have a function that returns a pdf file:
try{ $headers = [ 'Content-Type' => 'application/pdf', ]; return response()->download($file_path, $workspace['name'] . '_' .date("Ymd").'.pdf', $headers)->deleteFileAfterSend(true); }catch(Exception $e){ return $e->getMessage(); }
But I downloaded the pdf with blank content.
Does anyone have any thoughts on this issue?
In Laravel
In Vue js
answer
responseType is a sibling of headers, not a child
Thanks Phil for the help.