Re: Working with FormData as an object

On 14.5.2012 14:37, Anne van Kesteren wrote:
> On Mon, May 14, 2012 at 2:00 PM, Anne van Kesteren<annevk@annevk.nl>  wrote:
>> http://wiki.whatwg.org/wiki/FormData has some ideas on how we could
>> update FormData, XMLHttpRequest, and HTMLFormElement to address the
>> various use cases presented thus far. Feedback welcome.
> The one potentially problematic thing is exposing Blob passed to
> FormData as File since they always have a filename. This might give
> you distinct references to the underlying system file object. I'm not
> sure if that is problematic. If it is problematic, I am not sure how
> to keep the FormData API simple. I guess we should then introduce
> FormEntry objects and change the API proposal to work with those.
>
>
Hi,
before I start, it may not seem connected to it, but I'll get there :)
0/ toJSON method of Blob should be implemented (see 
http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf JSON.stringify, 
page 205, if anyone does not know). To create string representation of 
Blob or File, such object would expose all public properties (size, 
type, name, etc.) and content (either binary string ot data url).
WebKit (or Chromium, I'm not sure), actually implements something, 
JSON.stringify on file dropped displayes:
{"type":"image/png","name":"bauglir.png","webkitRelativePath":"","lastModifiedDate":"2011-06-01T14:44:18.000Z","size":7968}
but no data... no good
The question is whether this should not be async (but that would require 
alteration of ECMA method).

to FormData issue:
1/ we can go with something like
object toObject(boolean includeBlobs)
void fromObject(object Data, boolean include Blobs)

I hope the names are clear (I do not case about actual names, those are 
for being obvious). those methods would work as I described in 
http://lists.w3.org/Archives/Public/public-webapps/2012AprJun/0366.html
and they would either include or exclude working with blobs in either 
FormData (toObject) or object(fromObject) .
and if working with blob: append in form data 
(http://www.w3.org/TR/XMLHttpRequest2/#interface-formdata) has 3rd 
parameter form file, so internally this name must be stored somewhere 
before sending, so toObject can use it to determine, that such blob is 
actually a File and expose it as File (i do not know about 
lastModifiedData, but I do not care that much at this point). And 
fromObject can determine, whether blob value is Blob of File and use it 
to internally call append with appropriate parameters

2/ we can go with
string _toString(boolean includeBlobs) //or probably better name
void fromString(string someJSON, boolean include Blobs)
to do the same, but wirk with string representation (JSON),
and there is where i get to my 0/, stringification of Blob, because 
sure, we can go with 1/, I can get an object, and call JSON.stringify, 
but if such object would contain binary data, I'm lost, I cannot store 
it (or maybe IndexDB could be able, but that very limiting). And I would 
have to go through such object with some recursion and parse it on my own.


All those functions may need to be async (have a callback parameter to 
actually return data or signal end of parsing [one way or the other]), 
because of possible Blobs.

Brona

Received on Tuesday, 15 May 2012 21:38:18 UTC