multer 升级到1.0版本之后,发现用的复杂了,还是自己很水不会用。
发布于 4 个月前 作者 mrlong 345 次浏览 来自 问答

按着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);
})

屏幕快照 2015-09-20 23.33.52.png

3 回复

你的form里也要用 avatar,这样才对得上

name = “avatar”

回到顶部