带有远程文件的HTML5文件API [英] HTML5 File API with Remote File
问题描述
我想花几个小时来使用HTML5 FileSystem来添加一个带有URL的远程文件(例如 http:// example.com/doc.pdf )而不是由文件输入获得的文件,因为我希望进程是自动的(我有多个文档),但是我没有找到关于该进程的任何信息。
我发现的所有例子都与本地文件有关(添加了文件输入)...
我给你
$ b $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ c $ window $ request $ b FS_ = fs;
addRemoteDocuments();
},errorCallback);
函数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){
//捕获当前范围内的当前迭代文件getFile()回调。
函数(f){
FS_.root.getFile(getName(doc),{create:true,exclusive:true},function(fileEntry){
fileEntry。 createWriter(fileWriter){
fileWriter.onwriteend = function(e){
console.log('Write for doc'+ i);
};
fileWriter.write(GET_REMOTE_FILE(doc));
},errorCallback);
},errorCallback);
})(doc);
}
readDirectories();
函数GET_REMOTE_FILE(doc){
//无法找到获取文件的方法(可能使用file.name和其他属性)
}
也许通过模拟点击隐藏文件输入(如果可以添加远程文件.. 。)
我希望有人能帮助我,因为有关远程文件和文件系统的文档很难找到...
谢谢大家:)
。
我的关于HTML5Rocks的文章对此进行了深入讨论,并提供了完整示例一>。
它涉及XHR2 + Filesystem API。
I am trying for hours to use the HTML5 FileSystem to add a remote file with an URL (like http://example.com/doc.pdf) instead of the file obtained by the file input because I want the process to be automatic (I have more than one doc) but I didn't found anything about the process...
All examples I found concern local files (added with a file input)...
I give you few lines of my code :
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)
}
Maybe with a simulated click to a hidden file input (if it's possible to add a remote file...)
I hope somebody can help me because the docs about remote files and filesystem are difficult to find...
Thanks everybody :)
Brice.
My article on HTML5Rocks discusses this in depth and gives a full example. It involves XHR2 + the Filesystem API.
这篇关于带有远程文件的HTML5文件API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!