Multer not parsing the form data. Always shows undefined
See original GitHub issueI 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:
- Created 6 years ago
- Comments:8 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@LinusU … hey, it got resolved when i remove the content type … thanks 👍
How are you posting to the server? Are you using
enctype="multipart/form-data"
on your form?