save and change the name of the file with chrome.filesystem

扶醉桌前 提交于 2019-12-12 01:55:39

问题


Is this possible with chrome.fileSystem to save a file on the client's disk, but by changing the file name. For example, I compress a file and I want that file is stored on the disc with my new name newFile.min.js for example. I can save the file to disk, but not to change its name. And what I would like is that everything is done in a "silent" without a window that asks for the location.

Here is the function I use to save my files:

    function saveToEntry(entry, result) {
  setTitle();

  var blob = new Blob([result], {type: 'text/plain'});
  currentEntry.createWriter(function(writer) {
    writer.onwrite = function() {
      writer.onwrite = null;
      writer.write(blob);
    }
    writer.truncate(blob.size);
  });
}

function setTitle() {
  chrome.fileSystem.getDisplayPath(
      currentEntry,
      function(path) {
console.log(path);
        document.title = path;
      });
}

Is this possible? And if so, if you have any example to guide me would be great. If not, would be great too :)

Thank you in advance for your advice!


回答1:


For that (saving in a separate file), I'm afraid that you need to ask the user for write access for a folder, not an individual file. Then you will be able to create a new file in it.

I suggest that you either ask the user to select a "working" directory, present an in-app file picker from that folder, and save the result next to the normal file.

Alternatively, ask the user to select an "output" folder, and dump the results there.


Another solution would be to require a Native Host module. You'll be able to access the system with the same rights as the user. It will limit your deployment options though: you'll need a separate installer for your module that can't be hosted on Chrome Web Store.



来源:https://stackoverflow.com/questions/28460704/save-and-change-the-name-of-the-file-with-chrome-filesystem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!