Please add constructors for File and FileList

Dear Web Applications WG,

1) Please add a File constructor.

The ability to create a File was lost when BlobBuilder was deprecated
in favor of the Blob constructor. I think the easiest way to get it
back would be to have a File constructor that works
similarly to the Blob constructor, except that the property bag
accepts an extra 'name' property.

new File(["<p>Hello world!</p>\n"], { type: "text/html", name: "hello.html" });

There were a couple of threads on this issue before.

>From what I understand, the main issue seems to be the lack of a good
use case for a File constructor, so I would like to supply a few.

As a library developer, being able to create File instances would
allow me to write unit tests that cover all the inputs my library
takes, which would improve the quality of my code. For example,
Chrome's FileSystem API allows me to create File instances in a very
round-about way. This allowed me to find a browser bug (linked below),
and my library now works around it. The File-related test is disabled
on Firefox, because I cannot build File instances.

The other applications assume my next wish comes true, so I will list
them in a few paragraphs.

2) Please add a FileList constructor.

What I really want is "some way to add files to an <input
type="file">" listed in

I think that one reasonable way to get there is to have a FileList
constructor that takes an array of File instances, and have the
ability to assign that FileList to the files attribute of the <input>.
This avoids making FileList mutable.

This would also help me write better tests for my code. Currently,
<input type="file"> is the only form field whose value can't be set
inside JavaScript, so I can't write automated tests for <input
type="file">-related code.

Asides from improving testing, this would allow me to implement the
following _easily_:

* "filters" for uploaded content (e.g. resize a big image before uploading)
* "saving" the file a user selected in an IndexedDB, and "loading" it
back into the <input type="file"> if the page is accidentally

These features can be implemented without FileList support, but they
impact the application's design. For example, filters can be
implemented using FormData from XMLHttpRequest level 2 to upload
Blobs, but switching from plain form submission to XHR-based
submission can impact other parts of the application code, whereas
changing the files behind the <input> would be a localized change.

Thank you for your consideration,
    Victor Costan

Victor Costan | | | +1 (646) 434-8887
Massachusetts Institute of Technology
Department of Electrical Engineering and Computer Science, B.S. '07,
M.Eng '08, Ph.D. '14
Sloan School of Management, B.S. '07

Received on Tuesday, 11 December 2012 08:24:53 UTC