How to save image using javascript?

I'm working on a Chrome extension: dragging and dropping an image will save it to your computer.
I found out that HTML5 has the FileWriter API, but I really can't find any example, and does Chrome support it?

+7
source share
3 answers

No, HTML5 does not have the FileWriter API. What you probably mean is the File API , which allows you to read files. And in Chrome, even extensions are not allowed to write files for security reasons. Therefore, if you do not want to associate the NPAPI plugin with your extension (which will cause a huge warning during installation), all you can do is run a download message that the user can accept - or not. See Cross Browser Save as .txt for a possible approach (Flash objects such as Downloadify are different). A.

Change I was wrong, there is a suggestion of the FileWriter API. It is very far from doing this.

+3
source

I do not think the FileWriter API will be ready and useful for some time.

You can get the image data in hexadecimal format, and then use DataURI to β€œexport” from the browser. Although this leads to saving the file with the file name, such as "download (1)". Each browser seems to have different size restrictions for DataURI, and they are small, although it should be fine for an image with a reasonable size.

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

Alternatively, you can use Downloadify to save it with the correct file name (flash memory is required and it can be difficult to embed in the chrome extension).

http://davidwalsh.name/downloadify

+1
source

All Articles