1

Can someone please tell me what's wrong in my below code? I've been debugging this for hours but no luck.

var multer  = require('multer')
var upload = multer({ dest: '/uploads/' })
router.post('/image', upload.array('file', 12) , function(req, res) {
  console.log(req.body, req.file);
  // I got this here {} undefined

});

cilent

<form method="post" action="/products/image" enctype="multipart/form-data">
    <input type="file" name="file">
    <input type="submit" value="Upload">
</form>
nbro
  • 15,395
  • 32
  • 113
  • 196
Thian Kian Phin
  • 921
  • 3
  • 13
  • 25
  • If you use `upload.array` I guess that only `req.files` (and **not** `req.file`) is defined. Change `req.file` to `req.files` to see if it outputs something. If you solve your problem, please share the answer with us, because it could be useful for visitor users with your same or similar problem. – nbro Jan 09 '16 at 19:32

2 Answers2

0

I noticed that on the server you use /image but on the client /products/image. It could be the problem, if not - please share all your server source code.

0

try to use req.files with 's', instead of req.file