Assuming you’re using the express server, use the res.download
It transfers the file on the way as a attachment
:
var express = require('express');
var router = express.Router();
router.get('/download', function (req, res, next) {
var filePath = "/Users/meuuser/PDFs"; //caminho do arquivo completo
var fileName = "report.pdf"; // O nome padrão que o browser vai usar pra fazer download
res.download(filePath, fileName);
});
Note: There is the res.attachment
, but if Voce uses it, it will set the header Content-Disposition
as "Attachment" and this will make the browser understand that it should be viewed as an attachment, not a webpage. When you use res.download
, he transfers the file as attachment, so usually browsers will consider downloading the file.
Reference: Express Documentation res download..