0

I am developing a amozilla addon , and I have to download a file that is stored in the server. I would retrieve the file from the server using xmlHttpRequest. My question is how I download the response file in my browser from my mozilla addon

Muthu
  • 337
  • 6
  • 19

1 Answers1

0

You can use xmlHttpRequest with requestType of arrayBuffer, then use OS.File to write that to file: https://stackoverflow.com/a/25492679/1828637

This way does not show in the download manager, if you want it to show in the manager then you should use Downloads.jsm module: https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/Downloads.jsm

Community
  • 1
  • 1
Noitidart
  • 35,443
  • 37
  • 154
  • 323
  • Solution in the post http://stackoverflow.com/a/25492679/1828637 suits me , but the directory where the file has to be stored must be decided by the user. i.e. A **Save As** box must prompt for the download directory. How could I achieve this from your solution? – Muthu Nov 02 '15 at 13:21
  • @muthu: use nsIFilePicker with `modeGetFolder`: https://github.com/Noitidart/Icon-Container-Generator/blob/c196fb5db9eb41b5478f898658b8db175c99920f/resources/scripts/app.js#L250-L259 – Noitidart Nov 04 '15 at 03:33