I want to preview pdf first and then let user download by themself, also provide default name when downloading.
This is the code:
var data =fs.readFileSync('/Users/my/Desktop/demo.pdf');
res.contentType("application/pdf");
// res.setHeader('Content-Disposition', 'attachment; filename=my.pdf');
res.send(data);
Here if I do not set fileName, it will preview immediately in browser, but if I set fileName, it will download immediately.
1