Re: File API Feedback

Michael Nordman wrote:
> On Tue, Jul 21, 2009 at 6:20 PM, Arun Ranganathan <arun@mozilla.com> wrote:
>
>   
>> Michael Nordman wrote:
>>
>>     
>>> The BlobBuilder.append() method is central to the use-case I'm referring
>>> to.
>>> builder.append(string data that comprises the multipart/form-data header);
>>> builder.append(string data that comprises simple text part);
>>> builder.append(string data that comprises the start of a binary part);
>>> builder.append(fileBlob); // the file itself
>>> builder.append(string data that closes the binary part);
>>> // perhaps more binary and text parts
>>> builder.append(string data that closes the multipart/form-data);
>>> multipartBlob = builder.getAsBlob();
>>>
>>>
>>>       
>> OK, I understand your use case much better now :)
>>
>> So, currently, we provide a fileData.getAsText(fileCallback, encoding,
>> error)
>>
>> and
>>
>> within fileCallback (a callback function) you can get the file's data as a
>> string (say a UTF-8 encoded string, or any encoding specified by
>> "encoding"); it is passed as an argument to fileCallback.
>>
>> Then, you can append to the string (or prepend, in the case of the header)
>> using the standard JavaScript string methods.  And you can, of course, post
>> the string via XHR.
>>
>> Along with a similarly asynchronous splice method to generate "ranged"
>> subsets of a FileData object, I think that we've got *most* of the features
>> exposed by both BlobBuilder and Blob.
>>     
>
>
> I don't follow... how would you use the FileData and XHR2 apis to do what I
> outlined with blob builder... can you show me in a similar amount of pseudo
> code?
>   
Note that some things are possible already in Fx3.5.1 [1], but that when 
File API is released as spec., are likely to become deprecated (or at 
least, Fx-only).

For example:

http://hacks.mozilla.org/2009/06/xhr-progress-and-richer-file-uploading-feedback/ 


shows what can be done currently with non-standard file APIs in Fx3.5.1, 
and XHR.

Calls of the sort:

file.getAsText("utf8")

are non-standard, but today, you can append or prepend to that string 
(or concatenate it) and then post it using XHR (xhr.send(string) ).  So 
you could add multipart/form-data headers and stuff (or multipart/mixed, 
etc.).

My idea is:
 
var file = fileList.files.item(0);

if (file)
{
    // ... Make asynchronous call
    
    file.getAsText(handleText, "UTF-16", handleError);
    // ....
 
}

function handleText(fileAsUTF16)
{
   if(fileAsUTF16)
   {
       // append or prepend to the above string

      // use xhr.send(postString)
   }
}

This still sends strings, but XHR 2[2] has got:

  void send(in ByteArray data);

which makes me think we need a binary getter as well :)

-- A*
[1] https://developer.mozilla.org/en/nsIDOMFile
[2] http://www.w3.org/TR/XMLHttpRequest2/#xmlhttprequest

Received on Wednesday, 22 July 2009 02:14:40 UTC