compli
compli

Reputation: 61

Formdata is passing null value in req.body nodejs

I am passing a uploaded file through formdata from client to server, and the request by the server received has empty body. Here is the code, can someone please help?

Client side code -

enter image description here

Server side code -

enter image description here

enter image description here

OUTPUT -

browser console -

browser console

nodejs console -

enter image description here

Upvotes: 0

Views: 1056

Answers (2)

Andrey Bessonov
Andrey Bessonov

Reputation: 348

Your content-type will be

multipart/form-data

Not an application/json

Try to make something like this: https://programmingwithmosh.com/javascript/react-file-upload-proper-server-side-nodejs-easy/

Upvotes: 1

Mohamed Oraby
Mohamed Oraby

Reputation: 1036

You need to use a middleware like multer to parse form-data

Upvotes: 2

Related Questions