Last active
December 6, 2019 11:19
-
-
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 file contains hidden or 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
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'); | |
} | |
); |
This file contains hidden or 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
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