使用chrome.filesystem保存并更改文件的名称 [英] save and change the name of the file with chrome.filesystem

查看:2053
本文介绍了使用chrome.filesystem保存并更改文件的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能与chrome.fileSystem保存客户端磁盘上的文件,但通过更改文件名。例如,我压缩一个文件,我希望这个文件以我的新名字newFile.min.js存储在光盘上。我可以将文件保存到磁盘,但不能更改其名称。我想要的是,所有的事情都是在无声的情况下完成的,没有一个窗口要求的位置。

这是我用来保存我的文件的功能:

  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);
});


函数setTitle(){
chrome.fileSystem.getDisplayPath(
currentEntry,
函数(路径){
console.log (path);
document.title = path;
});
}

这可能吗?如果是这样的话,如果你有任何的例子来指导我会很棒。如果没有的话,会太​​棒了:)

预先感谢您的建议!

解决方案为此(保存在一个单独的文件中),恐怕你需要询问用户对文件夹的写入权限,而不是单个文件。然后你就可以在其中创建一个新的文件。



我建议你或者要求用户选择一个working目录,提供一个应用内文件然后将结果保存到普通文件旁边。另外,也可以让用户选择一个输出文件夹,并将结果转储到那里。

/ p>




另一个解决方案是要求 Native Host模块。您将能够以与用户相同的权限访问系统。但是,它将限制您的部署选项:您将需要单独的模块安装程序,无法在Chrome网上应用店中托管。


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!

解决方案

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.

这篇关于使用chrome.filesystem保存并更改文件的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆