0

I haven't had this problem before and I've been doing it this way a long time.
(Angular Frontend)


const myFormData = new FormData();
myFormData.append("ok","true");
this.http.put(my_Express_backend_url,myFormData);

(Express Backend)

body-parser=require('body-parser');
...

console.log(req.body.ok)
undefined

everything is hitting right, the routes, the controller, it's getting to the proper function, but for some reason it does not work with the form data. I've used this method many times before and it is almost entirely identical yet I receive the undefined for the function i just wrote.

for now I am simply using javascript objects to pass info, eg:

const wantFormData={ok:'false'};
this.http.post(my_url,wantFormData);

...

console.log(req.body.ok);
...
false

But if somebody can help me get this back to normal I would greatly appreciate it! Thank you!

1 Answer 1

0

I think body-parser only works with JSON or text data. Take a look at http://expressjs.com/en/resources/middleware/body-parser.html and Parsing Post Form Data Node.js Express

For parsing FormData, you might need another package.

Sign up to request clarification or add additional context in comments.

1 Comment

But the backend is currently working with other FormData() objects in the format of req.body.<_x_ > So I don't think I need to add anything new, but rather something in the way disabling the functionality or something unique that disables its ability to read this format of request contents.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.