W3C home > Mailing lists > Public > public-webapps@w3.org > April to June 2012

Re: File constructor

From: Jonas Sicking <jonas@sicking.cc>
Date: Fri, 11 May 2012 11:38:36 -0700
Message-ID: <CA+c2ei8zFfWGs6pgDkfwmCLMF2bh9Qx1Dq5aiUoo7wzvzK6Eug@mail.gmail.com>
To: Bronislav Klučka <Bronislav.Klucka@bauglir.com>
Cc: "public-webapps@w3.org" <public-webapps@w3.org>
On Fri, May 11, 2012 at 7:06 AM, Bronislav Klučka
<Bronislav.Klucka@bauglir.com> wrote:
> Hi,
> currently File object cannot be constructed, only Blob can.
> I'm currently implementing XHR blob upload, that blob can either be File
> (selected by user) or programatically created Blob.
> On server side :
> 1/ In case of File, I get file name as part of the file metadata (name,
> size, type, etc)
> 2/ In case of Blob, I cannot specify name and I have to send it as
> additional parameter and ignore name metadata
>
> sending multiple files/blobs at once can be a mess
>
> is there a reason, while File cannot be created? It is Blob with has name
> and lastModifyDate .
> http://dev.w3.org/2006/webapi/FileAPI/#file
>
> Could there be File constructor, that would work as Blob constructor with
> 3rd parameter specifying the name of the file and lastModifiedDate set to
> creation date

The use-case that you bring up is the ability to specify a filename
when sending a Blob using XMLHttpRequest.

Note that the only way XMLHttpRequest uses the name of a *File* object
is when you use a FormData object. When you do, the name of the File
is encoded in the multipart/form-data encoding.

You can accomplish the exact same thing when using Blob objects by
passing a third parameter when appending a Blob to a FormData.

If you don't want to use FormData but rather send the Blob/File
directly using XMLHttpRequest, you're basically on your own and have
to specify the filename using setRequestHeader. There is no difference
between Blob and File here.

/ Jonas
Received on Friday, 11 May 2012 18:39:35 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 18:49:52 GMT