Re: Proposal for sending multiple files via XMLHttpRequest.send()

On Fri, Sep 11, 2009 at 11:46 PM, Jian Li <jianli@chromium.org> wrote:
> Thank you for all your great feedbacks.
> Yes, the first approach is simpler and it requites far less work from the
> author and thus less error prone. However, I think the second approach does
> provide more flexibilities that might fit for the different data assembling
> and sending purpose. The author can use it to upload multiple attached
> files, save a set of client generated items, or even send any combinations
> of string data and file data.
> For example, the presentation web application wants to save a set of client
> generated slides to the server. Some of slides include attached files, like
> a video clip. It will be much easier for the author to send all the data to
> the server via the second approach:
>     var payload = new Array;
>     payload.push(header_for_slide1);
>     payload.push(data_for_slide1);
>     payload.push(header_for_slide2);
>     payload.push(data_for_slide2);
>     payload.push(attached_file1_for_slide2);
>     payload.push(attached_file2_for_slide2);
>     ...
>     xhr.send(payload);
> Since XMLHttpRequest spec has already added the overload for send(document),
> why not just adding more overload for file and array of items? IMHO, having
> similar send*** methods, like sendFile, together with overloads of send()
> might make the API more complicated.

It does seem useful to allow sending textual data combined with file
data. So if you do something like:

xhr.send(["foo", file, "bar"]);

then that would send the string "foo", concatenated with the data from
the file, and then finally the string "bar". The string data would be
UTF8 encoded. In the future we can also add support for ByteArrays (or
whatever they'll end up being called) combined with anything else.

However, a problem is that

xhr.send(["foo", "bar"]);

is defined to send "foo,bar". It would seem weird if array handling
changes just one of the items in the array is a file. One possible
solution is to add additional 'send' methods.

/ Jonas

Received on Saturday, 12 September 2009 07:46:57 UTC