-
-
Save fitsum/affc7fecc36b9e3b5c14d15fc3f722a7 to your computer and use it in GitHub Desktop.
Stream local pdf file from nodejs (restify) server to client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server.get('/downloadPdf/:fileData', function (req, res) { | |
// config | |
var fileData = Buffer.from(req.params.fileData, 'base64'); | |
var menuData = JSON.parse(fileData.toString()); | |
var userName = menuData.userName; | |
var menuName = slug(menuData.menuName); | |
var fileName = userName + "-" + menuName + PDF_EXT; | |
var filePath = PDF_PATH + fileName; | |
// process headers | |
res.writeHead(200, { | |
"Content-Type": 'application/octet-stream', | |
"Content-Disposition": "attachment; filename=" + fileName | |
}); | |
// process Data | |
var readStream = fileSystem.createReadStream(filePath); | |
readStream.pipe(res); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment