views:

1540

answers:

3

Hi, I'm currently creating an extension for google chrome which can save all images or links to images on the harddrive.

The problem is I don't know how to save file on disk with JS or with Google Chrome Extension API.

Have you got an idea ?

A: 

Since Javascript hitch-hikes to your computer with webpages from just about anywhere, it would be dangerous to give it the ability to write to your disk.

It's not allowed. Are you thinking that the Chrome extension will require user interaction? Otherwise it might fall into the same category.

pavium
+1  A: 

There's no way that I know of to silently save files to the user's drive, which is what it seems like you're hoping to do. I think you can ASK for files to be saved one at a time (prompting the user each time) using something like:

function saveAsMe (filename)
{
document.execCommand('SaveAs',null,filename)
}

If you wanted to only prompt the user once, you could grab all the images silently, zip them up in a bundle, then have the user download that. This might mean doing XmlHttpRequest on all the files, zipping them in Javascript, UPLOADING them to a staging area, and then asking the user if they would like to download the zip file. Sounds absurd, I know.

There are local storage options in the browser, but they are only for the developer's use, within the sandbox, as far as I know. (e.g. Gmail offline caching.) See recent announcements from Google like this one.

sandover
+1  A: 

Maybe take a look at NPAPI plugin. Another way to do what you need is simply send a request to an external website via XHR POST and then another GET request to retrieve the file back which will appear as a save file dialog.

Update: Once Google Chrome releases the HTML5 File API for writing, you can use that instead of the NPAPI plugin.

Mohamed Mansour
It's not the first time we are redirecting me on the NPAPI. I will take a look at it. Thank you for your help
X-Blaster
Note that if you plan to upload the extension to Google's gallery, using NPAPI will delay your publishing for a long review by them and it may even not end up accepted.
Max Shawabkeh
I agree with Max. It will delay publishing since it will be manually reviewed. It would be best if you have an external server that you can give access within your extension and upload the data via POST and fetch it back via GET with proper headers.
Mohamed Mansour