sindresorhus / ky

🌳 Tiny & elegant JavaScript HTTP client based on the browser Fetch API
MIT License
11.82k stars 341 forks source link

FormData & Files Encoding #570

Open bim-oulabi opened 3 months ago

bim-oulabi commented 3 months ago

Trying to post a formdata shows weird symbols as shown in the screen shot when and only when a file is appended to the formdata and when the values are in non-english language,

form example

const formdata = new FormData();
formdata.append('file', {SomeFileFromAnInput}, 'filename.pdf');
formdata.append('name','هلا هلا');

ky.post('/demo', {
  body: formdata
});

with ky

image

with plain fetch

image
sholladay commented 1 week ago

Strange! Is the file necessary to reproduce the problem? I can't reproduce, at least with just name on its own.

The raw request body that I see in Safari is:

------WebKitFormBoundaryJfZe6JJ5hninzVux
Content-Disposition: form-data; name="name"

هلا هلا
------WebKitFormBoundaryJfZe6JJ5hninzVux--
bim-oulabi commented 1 week ago

Yes the file is necessary to reproduce it,

Somehow it works fine in the BE and data is recieved correctly if parsed