directory-upload icon indicating copy to clipboard operation
directory-upload copied to clipboard

It is unclear how FormData object gets populated when Upload API is used

Open smaug---- opened this issue 8 years ago • 7 comments

Upload API is async, but FormData[1] let's one to query items synchronously.

https://xhr.spec.whatwg.org/#interface-formdata

smaug---- avatar Jun 19 '16 18:06 smaug----

@bakulf

smaug---- avatar Jun 19 '16 18:06 smaug----

What I'm proposing to fix this issue is to change for FormDataEntryValue in this way: typedef (Blob or Directory or USVString) FormDataEntryValue;

Would be also nice to add:

partial interface FormData { void append(USVString name, Directory value); void set(USVString name, Directory value); }

bakulf avatar Jun 20 '16 10:06 bakulf

How does that help with the asynchronousness?

smaug---- avatar Jun 20 '16 10:06 smaug----

All the querying can happen synchronously if we return Directory object instead its content. Right?

bakulf avatar Jun 20 '16 11:06 bakulf

Oh, I see. Yeah, that would work, so FormData object creation. It is just that FormData itself wouldn't actually have a sync way to check what all gets submitted since uploading would actually need to traverse through all subdirectories etc. And that would need to be synchronous. Can we make it async?

smaug---- avatar Jun 20 '16 12:06 smaug----

That requires big big changes to the FormData object. I prefer to expose the Directory object and keep the 'serialization' of its content just as last step in the HTML Form Submission algorithm.

bakulf avatar Jun 20 '16 13:06 bakulf

Well, there is the option to make FormData creation async. Promise<FormData> createFormData(); in HTMLFormElement.

smaug---- avatar Jun 20 '16 16:06 smaug----