I want to send a PDF file to the client, I to it with .sendFile from Express. I works good in Chrome, with a Download link chrome save it, with a normal _blank link, chrome open it in a new chrome tab.
But in Mozilla, Safari and IE, the Browser display a message "The file is damaged" or adobe reader. Adobe Reader doesn't show this message when the pdf was loaded over chrome.
My code:
app.get('/ebooks/:file', function(req, res, next){
var options = {
root: 'ebooks/',
dotfiles: 'deny',
headers: {
'x-timestamp': Date.now(),
'x-sent': true,
'Content-Type': 'application/pdf'
}
};
var fileName = req.params.file;
res.sendFile(fileName, options, function (err) {
if (err) {
console.log(err);
res.status(err.status).end();
}
else {
console.log('Sent:', fileName);
}
});
});
Have anyone an idea why?
Varha