[whatwg] canvas, img, file api and blobs
Jonas Sicking
jonas at sicking.cc
Tue Feb 16 04:10:38 PST 2010
On Tue, Feb 16, 2010 at 4:01 AM, Stef Epardaud <stef at epardaud.fr> wrote:
> On Tue, Feb 16, 2010 at 03:48:04AM -0800, Jonas Sicking wrote:
>> If you have the FormData object [1], then why is it simpler to use
>> <form> submission?
>>
>> [1] http://dev.w3.org/2006/webapi/XMLHttpRequest-2/Overview.html#the-formdata-interface
>
> Unless I'm missing the point, I find it simpler to use a regular <form>
> submission, which would use the processed files as well as other <input>
> elements rather than build the XMLHttpRequest, build the FormData (via
> the constructor, unless we can obtain it from the filled-in <form> but I
> didn't see any mention of FormData in the HTML5 spec), then send the
> request and deal with the answer.
>
> If I can turn the contents of a <canvas> into a File (possibly via Blob
> and/or Storage), then replace the <input type=file>'s list of files,
> then all the submitting is done by the browser.
>
> I think it is simpler than doing it AJAX, which is not to say that the
> more complex AJAX way isn't better, I think both should be possible.
> Also it would be consistent with the fact that every other <input> type
> can be set/filtered by JS after user input, and still rely on regular
> <form> submission.
Ah, sorry, it is indeed the idea that you can get a pre-filled
FormData from a <form>. Something like:
formData = myForm.getFormData();
after which you can do:
formData.append("thefile", myProcessedFile);
xhr.send(formData);
This isn't in any spec yet, so the exact syntax might change, but it
won't get more complex than this.
/ Jonas
More information about the whatwg
mailing list