10

I'm wondering if, with the new File API exposed in Chrome (I'm not concerned with cross-browser support at this time), it would be possible to write back to files opened via a file input.

You can see an example of what I'm trying to accomplish here: http://www.grehz.com/ide.

I know I can use server side scripts to dynamically create the files and allow the user to download them normally. I'm hoping that there's a way to accomplish this purely client side. I had read somewhere that you can write to files opened via a file input. I haven't been able to find any examples of this, though I have seen passing references to a FileWriter class.

I would be completely not surprised if this wasn't possible though (it seems likely that there are security issues with this). Just looking for some guidance or resources.

UPDATE:

I was reading here: http://dev.w3.org/2009/dap/file-system/file-writer.html

As I was playing around in Chrome, it looks like FileSaver and FileWriter are not implemented, but BlobBuilder is. I can call getBlob() on the BB object, is there any way I can then save that without FileSaver or FileWriter?

UPDATE2:

I found this issue in the Chromium project: http://code.google.com/p/chromium/issues/detail?id=65615&q=FileSaver&colspec=ID%20Stars%20Pri%20Area%20Feature%20Type%20Status%20Summary%20Modified%20Owner%20Mstone%20OS

So it's clear that it hasn't been implemented in any version yet (however, no mention of FileWriter - although I believe FileWriter depends on FileSaver).

Moving away from that, I'm considering a server-side solution. When a user clicks save, the contents of the textarea is posted to a script that then writes to a page and is sent back as plaintext or whatever mime-type would be appropriate for the user to download. Any other suggestions? This solution is fine for a "save as" but it's a little clunky as a general purpose save button.

gregghz
  • 3,925
  • 7
  • 40
  • 69

2 Answers2

4

From: http://code.google.com/p/chromium/issues/detail?id=58985#c7

FileSystem is really the right place to store big files (which is what it sounds like you're doing) and is available in Chrome 9. I suggest you look at these alternatives.

Note the not-extensions label at the top left. It sounds like this may just be for Chromium OS. I emailed Jeremy, the developer who made this comment for clarification.

Update: Jeremy replied that extensions actually will get access to File API including writes, but that it will be confined to a sandbox. He also linked to some undeployed docs on the matter: http://code.google.com/p/html5rocks/source/browse/www.html5rocks.com/content/tutorials/file/filesystem/index.html?spec=svn1cbb2aab2d6954a56f3067d2d3b9e997215be441&r=1cbb2aab2d6954a56f3067d2d3b9e997215be441

crizCraig
  • 8,487
  • 6
  • 54
  • 53
  • I was thinking about doing something like this. It actually *is* for Chromium OS. I was lucky enough to get a Cr-48 sent my way. First thing I noticed was the lack of a decent IDE. So I started working on it. Reading and writing local files will hopefully not be the end ... I'll need ftp or other remote type solutions eventually. – gregghz Jan 13 '11 at 02:30
  • Cool, I'm working on a CSS editor specifically. I'm thinking of remote stuff too. Currently, I'm using the localStorage and web-sql storage. Eventually I may do a CDN type of remote saving service. Let me know if you have questions about your stuff (craigquiter+so on gmail). – crizCraig Jan 13 '11 at 17:41
2

No way that I know of to save until those apis are implemented - which may be some time off.

Wayne Brantley
  • 694
  • 6
  • 11
  • "which may be some time off" - anything more specific available? I found an unassigned bug for FileSaver, so I'm assuming it has a low priority. Perhaps it's related to the amount of debate around this particular feature? – gregghz Dec 27 '10 at 22:52