multer 升级到1.0版本之后,发现用的复杂了,还是自己很水不会用。
按着github上的例子还是出错。
<form id="addimgForm" method="post" enctype="multipart/form-data" action="/profile">
<input type='file' id='uploadedimg' name="file" accept='.jpg,.jpeg,.gif,.png,.bmp' ></input>
<button type="submit">上传</button>
</form>
var upload = multer({
storage: multer.diskStorage({
destination: function (req, file, cb) {
cb(null, './uploads/')
},
filename: function (req, file, cb) {
cb(null, file.originalname)
}
})
});
//var upload = multer({ dest: 'uploads/' })
app.post('/profile',upload.single('avatar'),function (req, res, next) {
// req.file is the `avatar` file
// req.body will hold the text fields, if there were any
console.log(req.file);
})