whatwg / xhr

XMLHttpRequest Standard
https://xhr.spec.whatwg.org/
Other
314 stars 129 forks source link

`FormData`: Accept `object` form in constructor #387

Closed silverwind closed 6 months ago

silverwind commented 6 months ago

What problem are you trying to solve?

The FormData constructor is unergonomic to use for manual construction:

const fd = new FormData();
fd.append("name", name);
fd.append("file", file);

It would be nice if it accepts a object form:

const fd = new FormData({name, file)});

What solutions exist today?

URLSearchParams() is a similar interface that gained support for object form in its constructor.

How would you solve it?

Extend the standard.

Anything else?

One drawback is that the filename argument to append can not be provided in object form, but I think it's a non-issue because users can easily generate named File objects from Blob.

annevk commented 6 months ago

Thank you, but this has already been reported as #202. Marking as a duplicate therefore.