I have a structure like this:
let post = new FormData();
post.append('content', document.querySelector('.textfield').innerHTML);
post.append('creator', creator);
post.append('post_date', Date.now());
and I try to make request with this form data above:
this.postsService.addPost(post).subscribe(data => {});
postsService:
let headers = new Headers();
headers.append('Content-Type', 'multipart/form-data');
return this.http.post('http://localhost:3000/posts/add', post,
{headers: headers}).map(res => res.json());
and in backend, in node.js I get req.body as undefined:
router.post('/add', (req, res) => {
console.log(req.body); //undefined
}
Why backend does not approve my FormData object?
Comments
Post a Comment