Here is frontend code (Angular):-
download(user) {
this.clientAPI.get(Endpoints.DOWNLOAD).toPromise()
.then(res => {
let blob = new Blob([new Uint8Array(res.file)], { type: 'application/zip' });
console.log('blob',blob);
let a = document.createElement('a');
a.href = (URL.createObjectURL(blob));
a.download = res.filename;
document.body.appendChild(a);
a.click();
a.remove();
// this.downloadComplete(user);
})
.catch(err => console.error("download error = ", err))
}
Here is my backend code (Node Js):-
exports.download = function (req, res) {
let file = process.env.NOCE_ENV === 'local' ? `${process.cwd()}/server/downloads/eFAST-Release-20.5.17.19.zip` :
`${process.cwd()}/server/downloads/eFAST-Release-20.5.17.19.zip`;
let filename = path.basename(file);
res.setHeader('Content-disposition', 'attachment; filename=' + filename);
res.setHeader('Content-type', "application/zip");
let filestream = fs.createReadStream(file);
// console.log('filestream',filenter code hereestream)
res.jsonp({ filename: filename, file: filestream });
};
I am able to download the file but that is not in zip format . that is in .txt format and zero byte.
Please have a look and let me know hpw can i do this ?