下面是我的api。
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');
});
});
});
在上面的 api 调用中,我正在压缩项目文件夹(在 npm 中使用存档器),当调用downloadProject时,我需要在浏览器中下载该文件夹。
在下面的行中,我试图在压缩时pom.xml
用我的本地文件替换 。pom.xml
zip.file('temp/pom.xml',{name:"web/pom.xml"});
但我无法做到这一点。这是复制pom.xml
文件。
原件和复制件都留在文件夹中。
任何人都可以请帮忙。提前致谢。