2

我正在尝试使用 HTML5 FileSystem 添加一个带有 URL 的远程文件(例如http://example.com/doc.pdf)而不是通过文件输入获得的文件,因为我希望该过程是自动的(我有不止一个文档)但我没有发现任何关于这个过程的信息......

我发现的所有示例都涉及本地文件(添加了文件输入)......

我给你几行我的代码:

window.requestFileSystem(TEMPORARY, 1024 * 1024 * 10,  function(fs) {
  FS_ = fs;
  addRemoteDocuments();
}, errorCallback);

function addRemoteDocuments(){
var docList = [ "http://cpbdev/html5tests/pdf/tarifs.pdf", "http://cpbdev/html5tests/pdf/tarifs1.pdf", "http://cpbdev/html5tests/pdf/tarifs2.pdf", "http://cpbdev/html5tests/pdf/tarifs3.pdf", "http://cpbdev/html5tests/pdf/tarifs4.pdf" ];

for (var i = 0, doc; doc = this.docList[i]; ++i) {

// Capture current iteration's file in local scope for the getFile() callback.
(function(f) {

  FS_.root.getFile(getName(doc), {create: true, exclusive: true}, function(fileEntry) {
    fileEntry.createWriter(function(fileWriter) {
      fileWriter.onwriteend = function(e) {
        console.log('Write completed for doc '+i);
      };

      fileWriter.write(GET_REMOTE_FILE(doc));
    }, errorCallback);
  }, errorCallback);
})(doc);
}

readDirectories();
}

function GET_REMOTE_FILE(doc){
  //Impossible to find a way to get File (with possibility to use file.name and others properties)
}

也许通过模拟点击隐藏文件输入(如果可以添加远程文件......)

我希望有人可以帮助我,因为关于远程文件和文件系统的文档很难找到......

谢谢大家 :)

布莱斯。

4

1 回答 1

2

我关于 HTML5Rocks 的文章对此进行了深入讨论并给出了一个完整的示例。它涉及 XHR2 + 文件系统 API。

于 2012-02-28T21:29:22.570 回答