[whatwg] Directory upload via <input type="file" directory>

Ian Hickson ian at hixie.ch
Wed Jul 28 14:22:50 PDT 2010


On Thu, 22 Apr 2010, John Gregg wrote:
>
> The use case is not about choosing a directory for some browser 
> functionality, it is really about choosing a directory that you want to 
> upload to a web page, such as a collection of photo albums.

This seems to be the exact semantic of <input type=file multiple>, the 
only difference is in the UI. But it seems that it's the _user_ who has to 
decide whether he wants to upload a whole directory or a bunch of files 
from many directories, so the _user_ should be the one who decides whether 
the UI allows whole-directory selection or just file selection.


On Sun, 25 Apr 2010, Ojan Vafai wrote:
> 
> What do you do when there are multiple files with the same name?

The spec doesn't preclude the filename from containing a relative path, 
nor does it preclude the files from all having the same name. What data is 
uploaded is really up to the browser here. We don't need a new control for 
this.


On Sun, 25 Apr 2010, Jonas Sicking wrote:
> 
> I can't really say that I can think of any very urgent use cases for 
> this. However only a minor tweak to specs would cover this. By allowing 
> the filename to contain a partial path you'd have this covered without 
> need for new input types. I think this has been discussed before.

It was never disallowed, but I've made it explicit.


On Wed, 28 Apr 2010, John Gregg wrote:
> 
> Assuming the use case is valid to upload an entire directory while 
> maintaining directory structure, how should the user choose the 
> directory?  That's the point I'm interested in settling and I think 
> we've mostly just circled around it.

That's "just" UI; we don't need to specify it. Different browsers can find 
different solutions. For example, one option would be for a browser to 
change the rendering of <input type=file> from the current typical UI:

   [_____________________________] (( Browse... ))

...to:

   [_________________________] (( Browse... | V ))

...where the drop-down shows:

   [_________________________] (( Browse... | V ))
          | Select multiple files...             |
          | Select directory...                  |
          | Take photograph from camera...       |
          | Record video from camera...          |
          | Record sound file from microphone... |
          `--------------------------------------'


On Sat, 24 Apr 2010, Anne van Kesteren wrote:
> 
> One other use case I know of is Transmission. It allows selecting of a 
> folder it keeps track of for new torrent files. When new torrent files 
> are added it starts the download process for them. I could imagine 
> something similar being useful for an image sharing site such as Flickr. 
> (This use case does not really fit on top of <input type="file"> 
> however.)

Right, that's more the realm of the File Writer API.


On Sat, 24 Apr 2010, J Ross Nicoll wrote:
> 
> The implementation in Firefox is to allow directories to be dropped into 
> the browser along with files. It passes them to the script with an empty 
> type attribute, and attempts to read them produce a directory listing. 

That sounds like a bug.


> I would suggest this is something the drag & drop API needs to be 
> expanded to cover explicitly; perhaps have "isDirectory" and "files" 
> attributes on the File object, to indicate that a file reference is 
> actually a directory, and to access the contents of that directory 
> respectively.

I don't see why we'd need to expose the directories themselves. Really 
only the files matter. The directories are just part of the file names.


On Sat, 24 Apr 2010, Ojan Vafai wrote:
> 
> We should leave it up to UAs to figure out what the right UI should be, 
> but adding input "directory" seems to me like it will confuse the UI 
> more. Ideally users can drop whatever they want onto a file input that 
> has "multiple" and it can be up to the web page to remove entries it 
> doesn't allow. The web page is in a much better position to give user 
> feedback (e.g. a photo site can warn that only image uploads are allowed 
> and that non-images won't get uploaded).

Indeed.

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'



More information about the whatwg mailing list