Can't open a PDF downloaded using res.send(data)-express

115 Views Asked by At

I am having trouble whit this simple piece of code:

fs.readFile('public/PDF/Booklet_nl.pdf', (err,data)=>{
if(err){
throw err
 
}

res.send(data);
 });

The file can be downloaded but I am not able to visualize the PDF in the browser.

1

There are 1 best solutions below

0
On

For that, You should set headers as following:

res.setHeader('Content-type', 'application/pdf');
res.setHeader('Content-Disposition', 'attachment; filename=application.pdf');
 res.send(data);