下载 Zip 文件后,我需要调用另一个函数来处理 ProcessZip 文件。但我无法在 .send()
之后触发函数 ProcessZipFile()
:
app.get('/', function (req, res) {
DownloadZipFile();
});
function DownloadZipFile() {
var file = fs.createWriteStream('./tmp/student.tar.gz');
s3.getObject(params
.on('httpData', function (chunk) {
file.write(chunk);
})
.on('httpDone', function () {
file.end();
})
.send();
}
function ProcessZipFile() {
//.....
}
最佳答案
据我所知,在向浏览器发送响应后,您无法调用函数。因为路线已经完成了。我有两个想法给你。
1:将您的 DownloadZipFile()
作为中间件,成功后您将转到 ProcessZipFile()
,然后发送 response()
2:创建一个新的路由,在其中调用 ProcessZipFile()
并通过 ajax 从前端调用此路由
关于node.js - 如何在node js中发送响应后调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43203345/