Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Downloading files with a Firefox addon

I'm new to Firefox addon development, and it's going well so far, but I'm stuck on how to, essentially, download a file from the Web, given a URI, and save it to disk. Mozilla's MDN documentation has information on how to upload files, but the downloading files section is empty and yet to be written. Sadly, I haven't found any documentation which describes how to do this.

Does anyone know of relevant documentation on how to do this?


The old Facebook Photo Album Downloader addon uses this function call in its overlay JavaScript:

saveURL(images[i].replace(/\/s/g, "/n"), null, null, false, true, null);

Obviously, the first argument is the URI to request. The saveURL function isn't defined anywhere, so I assume it's an extension API function. I have tried it in my new addon, and it does work. I would, however, like to know what the other arguments mean.

like image 727
Delan Azabani Avatar asked Jul 12 '11 12:07

Delan Azabani


People also ask

Why is Firefox not allowing downloads?

Configure Internet security software Check the settings in your security software to see if there is an setting that may be blocking downloads. To diagnose whether Internet security software is causing problems, you can try temporarily disabling it, seeing if downloads work, and then re-enabling the software.

Does Firefox have a download manager?

Extension MetadataIt's an official Firefox extension by Free Download Manager developers. The sole purpose of this add-on is integration with FDM. FDM is a fast and reliable download manager and accelerator that improves your experience with downloads and helps you organize them in an easy manner.

How do I add a download extension to Firefox?

Download the file to your local computer. , click Add-ons and Themes and select Extensions. To add the downloaded add-on to the list of available add-ons, drag and drop the file into the Add-ons window. The add-on is added to the list.


2 Answers

The standard way to do this is with nsIWebBrowserPersist:

var persist =
  Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"].
  createInstance(Ci.nsIWebBrowserPersist);
persist.saveURI(serverURI, null, null, null, "", targetFile);

See https://developer.mozilla.org/en/Code_snippets/Downloading_Files for more info.

like image 187
Matthew Gertner Avatar answered Sep 18 '22 13:09

Matthew Gertner


There actually is some MDN documentation on this: https://developer.mozilla.org/en/Code_snippets/Downloading_Files.

like image 20
Wladimir Palant Avatar answered Sep 20 '22 13:09

Wladimir Palant