我要检查表单字段是否为空,以及在上传文件之前是否更改了名称,但 multer 首先上传文件,然后填充 req.body。我正在使用 multer 作为中间件。
上传.js
checkField: function(req, res, next) {
//Here i want to check if req.body.field1, field2 are empty or not
//If empty res.send('Required fields are empty');
console.log(req.body); //This returns empty {}
},
module.exports = {
uploadFile: multer({
limits: {
files: 1
},
dest: '/upload/',
})
};
路由器:
app.post('/upload', upload.checkField, upload.uploadFile, function(req, res){});