Multer and Express/Node File Upload Multer and Express/Node File Upload express express

Multer and Express/Node File Upload


I've been working on this today. One thing I noticed is that is you are using upload.single(), the data you're looking for will be in req.file not req.files.

I'm not sure if that's your issue though.

FYI, this slimmed down example works for me:

server.js

var express = require('express');var app = express();app.use(require('./routes'));app.listen(8080);

routes.js

var express = require('express');var multer = require('multer');var upload = multer({ dest: '/tmp/' });var router = express.Router();/* POST saveblog router. */router.post('/saveBlog', upload.any(), function(req, res, next) {  console.log(req.body, 'Body');  console.log(req.files, 'files');  res.end();});module.exports = router;

I posted from Postman and got this output:

{ test: '1' } 'Body'[ { fieldname: 'asdas',    originalname: 'vcenter.png',    encoding: '7bit',    mimetype: 'image/png',    destination: '/tmp/',    filename: '92f425268efaa45cad31f67ec8f14c2d',    path: '/tmp/92f425268efaa45cad31f67ec8f14c2d',    size: 54834 } ] 'files'


Just rename req.file to req.files. It worked for me.