2012-02-28 69 views
2

我想了几个小时使用HTML5文件系统添加远程文件与URL(如http://example.com/doc.pdf)(我,因为我想要的过程是自动的通过将文件输入获得的文件,而不是有一个以上的文档),但我没有找到有关进程什么...HTML5文件API与远程文件

所有的例子,我发现关注本地文件(添加文件输入)...

我给你的几行我的代码:

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

也许用模拟点击隐藏fil输入E(如果有可能增加一个远程文件...)

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

谢谢大家:)

布莱斯。

+0

什么是你想怎么办?通过文件API下载远程文件? – mpm 2012-02-28 16:32:12

+0

我想将远程文件添加到本地文件系统。 (离线后访问它们) – Pouki 2012-02-28 16:35:36

回答

2

我上的HTML5Rocks文章讨论这个深度并给出a full example。它涉及到XHR2 + Filesystem API。

+0

嗨ebidel,感谢您的链接,这是我需要什么,但我有一个关于CORS问题,你说html5rocks.com已启用CORS上所有的网页,但如何把一个头PNG或PDF文件?因为当我尝试进入“http://www.html5rocks.com/en/tutorials/file/xhr2/access_control_header.png”,我没有看到的访问控制允许来源标头的形象和我无法获得该文件...对不起,如果我的问题是微不足道的 – Pouki 2012-02-29 13:43:15