7

I'm working on a Chrome Extension: when you drag an image, it will be saved to your computer.
I learned that in HTML5 there is FileWriter API, but really can't find any example of it, and does Chrome support it?

wong2
  • 34,358
  • 48
  • 134
  • 179

3 Answers3

3

No, there isn't a FileWriter API in HTML5. What you probably mean is the File API that allows you to read files. And in Chrome even extensions aren't allowed to write files, for reasons of security. So unless you want to bundle an NPAPI plugin with your extension (which would trigger a huge warning upon installation) all you can do is trigger a download message that the user might choose to accept - or not. See Cross-browser Save As .txt for a possible approach (Flash objects like Downloadify being the other).

Edit: I was wrong, there is a FileWriter API proposal. It is very far from being done however.

Community
  • 1
  • 1
Wladimir Palant
  • 56,865
  • 12
  • 98
  • 126
2

I found this. http://www.html5rocks.com/en/tutorials/file/filesystem/ You can find some examples.

Edit This is screenshot from the article. I'm using chrome 12.0

FileWriter API browser support message http://s3.amazonaws.com/twitpic/photos/full/329503613.png?AWSAccessKeyId=AKIAJF3XCCKACR3QDMOA&Expires=1308932374&Signature=DXBdFSjbNqaeJPr%2F0fSAqPWyh2E%3D

Sanghyun Lee
  • 21,644
  • 19
  • 100
  • 126
  • I see, there is apparently a proposal to allow read/write access to parts of user's disk contrary to what I said in my answer. This proposal is in early stages however and might never be implemented by any browser (the security questions seem still unsolved). – Wladimir Palant Jun 24 '11 at 15:28
  • @Wladimir The article says the chrome and my browser(chrome) appears to support all of the functionality used in this article. I'll upload the screen shot. – Sanghyun Lee Jun 24 '11 at 15:56
1

I don't think the FileWriter API will be ready and usable for some time yet.

You could get the image data in hex, then use a DataURI to 'export' it from the browser. Although this leads to a file saved with a filename such as "download(1)". Each browser seems to have different size limitations for DataURIs, and they're not big, although ahould be fine for a reasonably sized image.

http://en.wikipedia.org/wiki/Data_URI_scheme

Alternatively you could use a Downloadify to save it with a proper filename (Requires flash and may be tricky to embed into the chrome extension).

http://davidwalsh.name/downloadify

Mike
  • 93
  • 4