Here is my api below.
app.post('/downloadproject', function(req, res) {
var projectName = 'web';
res.set('Content-Type', 'application/zip');
res.set('Content-Disposition', `attachment; filename=${projectName}.zip`);
var zip = Archiver('zip');
var adminZip=require('adm-zip');
var zipper = new adminZip();
// Send the file to the page output.
zip.pipe(res);
zip.directory(`projects/${projectName}/`, projectName);
editPom(req.body,function(){
// zipper.addLocalFile('temp/pom.xml','web/pom.xml');
zip.file('temp/pom.xml',{name:"web/pom.xml"});
zip.finalize().then(function(){
console.log('Zip completed');
});
});
});
In the above api call I am zipping the project folder, (using archiver in npm), that I need to download in the browser when downloadProject is called.
In the below line I am trying to replace the pom.xml
with my local pom.xml
file while zipping.
zip.file('temp/pom.xml',{name:"web/pom.xml"});
But I am unable to do this. This is duplicating the pom.xml
file.
The original and copied one are both being left in the folder.
Can anyone please help. Thanks in advance.