[whatwg] Forms: <input type=file> and directory tree picking

Jonas Sicking jonas at sicking.cc
Thu Aug 29 14:09:11 PDT 2013

On Thu, Aug 29, 2013 at 1:20 PM, Ian Hickson <ian at hixie.ch> wrote:
> On Fri, 2 Aug 2013, Jonathan Watt wrote:
>> I'm working on Mozilla's implementation of <input type=file> to allow
>> the user to pick a directory. The idea would be that the files in that
>> directory and its subdirectories would be added to the
>> HTMLInputElement.files FileList.
> This seems to be dangerous in that it makes it really easy for the user to
> select a single item that expands into tens of thousands if not millions
> of files on a remote disk, which then all have to be synchronously
> enumerated to get the count so that code can then itself enumerate through
> the entire list.

We don't have to do any enumeration synchronously. It can all happen
off the main thread. The .click() "API" is asynchronous.

>> The advantage of avoiding the need for the 'directory' attribute would
>> be that directory picking would work for existing content with <input
>> type=file multiple> without needing to be changed. One disadvantage
>> would be that existing content may depend on the file names in the
>> FileList being unique.
> I would have liked the file names to still be unique, by prefixing the
> names with the relevant parts of the subpaths (that is, if I select
> foo.txt and bar/ which contains another foo.txt, .files would contain
> "foo.txt" and "bar/foo.txt"), but I think that ship sailed (and now the
> spec explicitly requires otherwise).

We discussed this. However many people has expressed that they expect
the .name property to only contain the leaf name. Trying to tell
people that the name is unique and may or may not include pieces of
path has lead to lots of confusion.

Instead we'll ensure that path+name is unique. At least unique within
a single selection. We're planning on eventually letting users bring
up filepickers multiple times and select additional files each time.

>> Currently authors can use HTMLInputElement.click() to open a system file
>> picker. To give content the ability to open a system directory picker
>> we'd add a corresponding .openDirectoryPicker() function.
> So you wouldn't be able to pick a file and a directory as in the example
> above? That seems unfortunate...

Unfortunately most OSs doesn't have support for filepickers that can
select either a file or a directory.

/ Jonas

More information about the whatwg mailing list