我正在使用multer来处理上传图片。
app.use(multer({ dest: './public/photos',
rename: function (fieldname, filename) {
return filename+Date.now();
},
onFileUploadStart: function (file) {
console.log(file.originalname + ' is starting ...')
},
onFileUploadComplete: function (file) {
console.log(file.fieldname + ' uploaded to ' + file.path)
//a='asass';
done=true;
}
}));
app.post('/api/photo',function(req,res){
if(done==true){ //ERROR here if I remove comment on 'a=asass' >> 'done' is not defined
console.log(req.files);
console.log(req.body);
res.end("File uploaded.");
}
});
我没有在任何地方声明“完成”变量,为什么这段代码仍然有效?如果我删除对“a = asass”的评论,我会在上面得到错误。(我不在任何地方声明“a”变量)。当我为变量赋值时,我应该得到错误,但它不会发生。