调用window.webkitRequestFileSystem两次会导致第一次调用不被绕过

时间:2016-02-07 15:30:12

标签: html5 file cordova blackberry-10

有一个有趣的问题......我正在制作一个BB10应用程序(我知道)并且正在使用window.webkitRequestFileSystem调用a)提供此应用程序已下载的本地文件列表,以及b)读取其中一个文件并显示内容 - 没什么了不起的。

单独地,我可以得到两个电话a)和b)工作;但是,当我将它们放在同一个函数中,希望同时显示一个文件列表并读取其中一个文件时,它会导致读取文件 at

在下面的示例中,无论列表调用是在读取呼叫之前还是之后,读取呼叫都不会触发,即,我将永远不会看到' fileentry'警报。

发生了什么?

function initFS(){
sharedFolder = blackberry.io.sharedFolder;

var path = sharedFolder+'/downloads';
//alert(path);

document.getElementById('plancontents').value="initialized";

window.requestFileSystem  = window.requestFileSystem || 
window.webkitRequestFileSystem;

//window.requestFileSystem(window.TEMPORARY, 1024 * 1024,
//window.requestFileSystem(LocalFileSystem.PERSISTENT, 1024*1024*5,
window.webkitRequestFileSystem(window.PERSISTENT, 1024*1024*5,
function (fs) {
    //fs.root.getFile(blackberry.io.sharedFolder 
    //fs.root.getFile('file:///accounts/1000/shared/downloads/filename.xml', {create: false},
    fs.root.getFile(sharedFolder+'/downloads/filename.xml', {create: false},
    function (fileEntry) {
        alert("fileentry");
        fileEntry.file(function (file) {
            var reader = new FileReader();
            //alert("trying to read file");
            reader.onloadend = function (e) {
                document.getElementById('plancontents').value = this.result;
            };

            reader.readAsText(file);
        }, errorHandler);
    }, errorHandler);
});

window.webkitRequestFileSystem(window.PERSISTENT, 1024*1024*5,
function (fs) {
    alert('FS requested and inside');

    fs.root.getDirectory(path, {}, function(dirEntry){
        alert('inside getDir');

        var dirReader = dirEntry.createReader();

        alert('created reader');

        dirReader.readEntries(function(entries) {
            alert('trying to list dir');

            for(var i = 0; i < entries.length; i++) {
                var entry = entries[i];

                if (entry.isDirectory) {
                    alert('Directory: ' + entry.fullPath);
                }
                else if (entry.isFile) {
                    alert('File: ' + entry.fullPath);
                }
            }
        }, errorHandler);
    }, errorHandler);
});

}

0 个答案:

没有答案