jimmywarting / FormData

HTML5 `FormData` polyfill for Browsers and nodejs
MIT License
360 stars 102 forks source link

Polyfill changes the media type #33

Closed petewins closed 6 years ago

petewins commented 7 years ago

In the console, the polyfill FormData shows as object Object and the native FormData is object FormData image

I believe this causes an error when it hits the server that only accepts multipart-formdata "{"status":null,"errorCode":400,"errorMessage":"The request could not be understood by the server due to malformed syntax.","response":"Content type 'application/json' not supported"}"

jimmywarting commented 7 years ago

Emh... why dose it say content type application/json?

can you show some code?

petewins commented 7 years ago

This is for an angular project

Import * as _FormData from 'formdata-polyfill';

let data = new _FormData();
let native = new FormData();

console.log('polyfill formdata, data);
console.log('native browser formdata', native);
spoike commented 6 years ago

@petewins The error you get is hinting that you can't send form data as JSON data rather than what the server expects. How do you send data to your server?

Form data (if implemented through form only) is by default POSTed with application/x-www-form-urlencoded set as Content-Type. Better check your server implementation.

jimmywarting commented 6 years ago

Nah @spoike , FormData is normally sent with content type: multipart/form-data; boundary=----xxxx'

If You send body = new URLSearchParams() you would get x-www-form-urlencoded

jimmywarting commented 6 years ago

Btw, v3 (released today) now sets the correct content-type header in fetch and xhr if not specified also calls _blob() transparently. Maybe you want to try to update the version?

petewins commented 6 years ago

@jimmywarting updated and working

jimmywarting commented 6 years ago

Woop woop, no open issues or PR everything is just perfect

anwar101 commented 6 years ago

hi all ,

I updated to V3 and same issue occur with me when send angular http post request Content-Type: application/json; charset=utf-8 ?

Please Advise