Skip to content

Instantly share code, notes, and snippets.

@ShivKumarSaini
Last active December 6, 2019 11:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ShivKumarSaini/13dc7f9ab3492d31784c3de0709ccd44 to your computer and use it in GitHub Desktop.
Save ShivKumarSaini/13dc7f9ab3492d31784c3de0709ccd44 to your computer and use it in GitHub Desktop.
File Download (Excel in this case) with Node Server and Angular 2+ App
this._httpService.get(<server url to download a file>
, {headers: new HttpHeaders({'Content-Type': 'application/octet-stream'}), responseType: 'blob'})
.subscribe(
(fileExcel) => {
fileExcel; // this is a blob.
},
(error) => {
console.log('err');
}
);
res.setHeader('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
res.setHeader('Content-Disposition', `attachment; filename=${options.root}/public/excel/${fileName}`);
res.download(<absolute path with filename>, fileName, options, function (err) {
if (err) {
if (!res.headersSent) {
res.send('OK');
console.log(res.headersSent);
}
next(err);
} else {
console.log('Sent:', fileName);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment