我正在使用Multer将多个文件上传到服务器。我尝试了不同的代码策略,但是总是在使用Express.js和Handlebars尝试了Multer的同时获得Undefined值,但是每次都获得Undefined值
Handlebrs:这是我的Handlebars文件
<form method="POST" action="/admin/newRequest"
enctype="multipart/form-
data" >
<input type='text' name="fname">
<input type="file" name="first">
<input type="file" name="doc2Request">
<input type="file" name="doc3Request">
<input type="submit" name="submit" id="" value="submit">
</form>
Multer Config:这是Multer配置
var multer = require('multer');
const multerConfig = {
storage: multer.diskStorage({
destination: function (req, file, cb) {
cb(null, './public/uploads/')
},
filename: function (req, file, cb) {
cb(null, file.fieldname + '-' + Date.now());
}
})
}
var upload = multer({ storage: storage })
路线:
route.post('/admin/newRequest', upload.any(), (req, res, next) => {
console.log(req.files);
console.log(req.body);
});
我想获取所有这四个输入的文件和输入。