我无法弄清如何将req.body.fname用作文件名,甚至尝试使用中间件,但req.body为空。
var storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, path);
},
filename: function (req, file, cb) {
cb(null, req.body.fname) // undefined
}
})
var upload = multer({ storage: storage })
app.get('/upload', upload.single('fname'), (req,res)=>{
.......
})
i m unable to figure out how to fetch fname in fileName
index.html
<form action="/upload" method="POST" enctype= "multipart/form-data">
<input type="text" name="fname">
<input type="file" name="pic">
<input type = "submit">
</form>