Multer : req.body is null
See original GitHub issueHello,
I’m trying to upload a file through an express API.
However when I try to fetch the body content, among the file, it gaves the following value : [Object: null prototype] {}
Here is the request that I’ve made with Postman :
As you can see, the file is the last element to be sent, it shouldn’t be a problem.
Here is my backend code :
app.post("/register/supplier",(req, res) => {
const storage = multer.diskStorage({
destination: (req,res,cb) => cb(null,__dirname + '/../files/kbis/'),
filename: (req,file,cb) => cb(null, file.name)
})
const upload = multer({ storage }).single('kbis')
upload(req,res,(err) => {
console.log(req.body,req.files)
})
return res.status(200).json({ message: 'testing' })
});
I know that a few people met this req.body
issue, and I tried to follow the proposed leads, but it didn’t resolve my issue.
Any ideas ? Thank you for your help !
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Node.js, multer and req.body empty - Stack Overflow
Note that req.body might not have been fully populated yet. It depends on the order that the client transmits fields and files to...
Read more >req.body will always empty when we use multer? #322 - GitHub
The problem is when I multer the req.body will always empty. ... destination: function (req, file, cb) { console.log(req.body) cb(null, ...
Read more >Multer — req.body null object when send file with other field ...
I was work in some project that built with NextJS as Front End and ExpressJS as Back End, when i create Rest API...
Read more >Express multer middleware
Note that req.body might not have been fully populated yet. It depends on the order that the client transmits fields and files to...
Read more >Handling any POST data in Express - CodeX Team
Request body data will be placed to req.body . A few examples for decoding popular request data formats: application/x-www-form-urlencoded; application/json ...
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 Free
Top 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
Oh you’re absolutely right, I didn’t pay attention !
Well, it works totally as expected, thank you a lot for your help 😄
Since you are using
.single(...)
the file will live atreq.file
(nos
)