Open AnkitBagaria24 opened 4 years ago
Same problem bro, did you solve it?
Any solution yet?
I solved using fileDownload ( https://www.npmjs.com/package/js-file-download ) and setting the axios response as "blob", here my code:
const res = await axios.get(
`/your/pdf/route`,
{
responseType: "blob"
}
);
await fileDownload(res.data, `${pdfName}.pdf`);
Works fine, i think file-saver works too, the problem maybe was the blob type.
I solved it.
import { saveAs } from 'file-saver';
axios.post('/get-file-content', formdata, {responseType: "blob"}).then((resp) => {
console.log('bokunReq', resp.data)
saveAs(resp.data, "ticket.pdf");
})
this is core {responseType: "blob"}
I am saving a pdf to my local machine, using saveAs from 'file-saver' library. Data is provided locally, it is not fetched from server.
Pdf is getting saved successfully, but while opening the pdf I am getting an error as File type plain text document (text/plain) is not supported though I am mentioning type as pdf.
Below is the code. I am developing the application using reactjs.
Attatching screenshot of the error