我尝试了几个小时使用 HTML5 文件系统添加带有 URL 的远程文件(例如http://example.com/doc.pdf 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)
}
也许通过模拟点击隐藏文件输入(如果可以添加远程文件......)
我希望有人可以帮助我,因为有关远程文件和文件系统的文档很难找到......
谢谢大家 :)
Brice.