Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save an image with JavaScript?

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?

like image 560
wong2 Avatar asked Jun 24 '11 15:06

wong2


People also ask

How do I save an image in a directory in JavaScript?

You cannot save image or file using javascript in local filesystem for security reason. Javascript and jQuery are purely client-side technologies and are not going to be able to handle something like saving a file to your local machine without using some server-side code.

How do I save a picture as a code?

Open the command palette (Ctrl+Shift+P on Windows and Linux, Cmd+Shift+P on OS X) and search for Code Snapshot . Select the code you'd like to screenshot. Adjust the width of the screenshot if desired. Click the shutter button to save the screenshot.


2 Answers

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.

like image 200
Wladimir Palant Avatar answered Sep 19 '22 04:09

Wladimir Palant


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

like image 32
Sanghyun Lee Avatar answered Sep 18 '22 04:09

Sanghyun Lee