Download and open Firefox

125 views Asked by At

I am a new user of Firefox's plugin system. I wanted to create a plugin that will download multiple files in a que, and then open them for practice.

My question is if there is a way to download a file from the Internet in the plugin. I am aware of os.file's existence (though it is not easy for me to understand how to use it from the examples provided). Next I would like to know if there is a way to execute the file using the default program for it.

1

There are 1 answers

0
Makyen On

As of Firefox 26, in Add-on SDK, restartless/bootstrap, or overlay based extensions, the most appropriate way to download a file from within an add-on is to use the Downloads.jsm JavaScript code module.

Downloading to a local file example from MDN Downloads.jsm page:

Components.utils.import("resource://gre/modules/Downloads.jsm");
Components.utils.import("resource://gre/modules/osfile.jsm")
Components.utils.import("resource://gre/modules/Task.jsm");

Task.spawn(function () {
  yield Downloads.fetch("http://www.mozilla.org/",
                        OS.Path.join(OS.Constants.Path.tmpDir,
                                     "example-download.html"));
  console.log("example-download.html has been downloaded.");
}).then(null, Components.utils.reportError);

If you want to initiate a download exactly as if the user had initiated it, then you should see my answer to How to launch a normal download from an addon.