我使用multiparty将图片上传到我的网络应用上传目录 问题是节点在显示页面之前不会等待上传图像。
我试图让它像这样工作:
app.post('/home', uploadAvatar, function(req, res) {
res.render('profile.ejs');
});
function uploadAvatar(req, res, next) {
var form = new multiparty.Form();
form.autoFiles = true;
form.uploadDir = './public/uploads/';
form.on('file', function(name,file){
console.log( 'New file uploaded to ' + file.path );
});
form.on('part', function (part) {
});
form.on("close", function() {
console.log('Upload completed!');
return next();
});
form.parse(req);
}
但是形式。('关闭')永远不会被调用。