question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multer not parsing the form data. Always shows undefined

See original GitHub issue

I am getting all three fields body, file and files as undefined no matter what I do … Please can anyone tell me what am I doing wrong.

var express = require("express");
var app = express();
var multer = require('multer');

var upload = multer({
  dest: 'images/',
});

app.post('/uploadchq', upload.single('file'), function(req, res, next) {
  console.log("file", req.file);
  console.log("files", req.files);
  console.log("body", req.body);
  next();
  res.sendStatus(200);
});

app.listen(9999);
console.log("listening to port", 9999);

This is another way in which I tried but it is still undefined.

var express = require("express");
var app = express();
var multer = require('multer');

var storage = multer.diskStorage({
  destination: function(req, file, cb){
    console.log("destination");
    var dest = 'images/';
    cb(null, dest);
  }
});

app.post('/uploadchq', upload.fields([{ name: 'file' }]), function(req, res, next) {
  console.dir("file", req.file);
  console.log("files", req.files);
  console.log("body", req.body);
  res.sendStatus(200);
});

app.listen(9999);
console.log("listening to port", 9999);

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
kirtanshettycommented, Apr 3, 2017

@LinusU … hey, it got resolved when i remove the content type … thanks 👍

1reaction
LinusUcommented, Apr 2, 2017

How are you posting to the server? Are you using enctype="multipart/form-data" on your form?

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - multer - req.file always undefined - Stack Overflow
In my case Multer couldn't parse the multipart form data / boundaries in the request body set by the client (a Java server)....
Read more >
Express multer middleware
Multer is a node.js middleware for handling multipart/form-data , which is primarily used for uploading files. It is written on top of busboy...
Read more >
req.file.path undefined multer - You.com | The AI Search ...
I am using multer module with express 4 to upload files to my application with a multipart form-data enctype on my form. I...
Read more >
Handling any POST data in Express - CodeX Team
multipart/form-data used for sending files or form-data objects. Express by default has no ability to parse this type of encoding. So you can...
Read more >
File uploads using Node.js - CodeForGeek
I am using this code to upload images into different folders it is working fine but i am not getting post data it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found