1

I know that I can use:

chrome.downloads.download({
   url: “http://your.url/to/download”,
   filename: “suggested/filename/with/relative.path” // Optional
 });

to save some file to a user specified location. Is there any way to make that location be a part of the extensions folder?

A few possible use cases:

  • Perhaps I wanted to allow the user to save a new icon to use for the extension.
  • Perhaps I wanted to allow the user to simply save files to be used by the extension without worrying about those files being manually deleted.
COMisHARD
  • 867
  • 3
  • 13
  • 36

1 Answers1

4

You can use the sandboxed filesystem api: https://www.html5rocks.com/en/tutorials/file/filesystem/

First, add the "unlimitedStorage" permission to the manifest.

Then, access the filesystem, write files, and access them via filesystem: urls

webkitRequestFileSystem(PERSISTENT, 1024, function(filesystem) {
 filesystem.root.getFile("test", { create: true }, function(file) {
  file.createWriter(function(writer) {
   writer.addEventListener("write", function(event) {
    location = file.toURL()
   })
   writer.addEventListener("error", console.error)
   writer.write(new Blob([ "test" ]))
  }, console.error)
 }, console.error)
}, console.error)
Daniel Herr
  • 19,083
  • 6
  • 44
  • 61