[whatwg] creating a new file via the File API

Ian Hickson ian at hixie.ch
Thu Dec 15 13:04:03 PST 2011


On Mon, 15 Aug 2011, David Karger wrote:
>
> Apologies if I'm revisiting old territory.  I've been doing work on pure 
> html/javascript applications that work entirely clientside 
> (http://projects.csail.mit.edu/exhibit/Dido).  For persistence, they 
> read and write local files.  There's already an <input type="file"> 
> interface for letting the user specify a file to be read.  And I can use 
> the same interface, inappropriately, to let the user overwrite a 
> preexisting file.  But things get much messier if I want to let the user 
> specify a _new_ file to be written, because the file-open dialog doesn't 
> offer users a way to specify a new filename.  What I'd like to be able 
> to do is specify a tag, or a invoke some javascript method, that will 
> produce the "save file" dialog typical of most systems, with a graphical 
> directory browser but including the option to specify a new filename.  
> This problem isn't unique to me; a discussion on stackoverflow appears 
> at 
> http://stackoverflow.com/questions/2897619/using-html5-javascript-to-generate-and-save-a-file 
> where the proposed solution is to use flash---and that would be an 
> unfortunate loss of html5 purity.  They also suggest the hack of using a 
> data: url but that has size limitations.
> 
> Perhaps <input type="file"> could be given an attribute specifying 
> whether a new filename is permitted?

On Wed, 7 Sep 2011, Eric U wrote:
> 
> This sounds like a job for the FileSaver interface.  Currently no 
> browser implements it, but we at Chrome have been considering it.  At 
> TPAC last year we discussed it a bit in the WebApps WG meeting; IIRC we 
> talked about letting it take a URL instead of or in addition to just a 
> Blob, for more general utility.
> 
> I suggest you bring it up on public-webapps@, where that spec lives. 
> http://dev.w3.org/2009/dap/file-system/file-writer.html#idl-def-FileSaver

I agree that an API like FileSaver is the right way to do this. Using 
<input type=file> wouldn't really fit well because that's more for 
providing data for upload than providing a file for writing.

-- 
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