Cordova 3.4 FileReader无法正常工作(没有onloadend)

Ves*_*lis 6 javascript filereader ios cordova

我正在将一个应用程序从phonegap 2.*更新到cordova 3.4现在运行顺畅,只有文件下载不起作用.

我需要从Internet(主机编辑)下载文件并将其存储为JSON文件,以便稍后处理内容.下载工作正常,文件将显示在文件系统中,但FileReader不会触发onloadend事件.

我试图像一些事情onprogressonerror事件,也file.toURIFileReader.readAsDataURL-毫无效果.有人有什么想法吗?

笔记:

  • app.log 可以看作是别名 console.log
  • print_r 在另一个文件中定义,工作正常
  • 下载的文件只有几KB,不应该是性能问题
  • 在iOS硬件上运行

完整代码(提取和缩短):

var fileTransfer = new FileTransfer();

var loadingStatus = 0;
fileTransfer.onprogress = function (progressEvent) {

    // if we have the complete length we can calculate the percentage, otherwise just count up
    if (progressEvent.lengthComputable) {
        loadingStatus = Math.floor(progressEvent.loaded / progressEvent.total * 100);
    } else {
        loadingStatus++;
    }
    app.log('Transfer Progress: ' + loadingStatus);

};

fileTransfer.download(
    encodeURI('http://www.example.com/export'),
    'cdvfile://localhost/persistent/import.json',
    function (file) {

        var FileReader = new FileReader();

        FileReader.onloadend = function (evt) {
            app.log('Filereader onloadend');
            app.log(evt);
        };

        FileReader.readAsText(file);

    },
    function (error) {

        // FileTransfer failed
        app.log("FileTransfer Error: " + print_r(error));

    }
);
Run Code Online (Sandbox Code Playgroud)

小智 6

File API已更新.请参阅此帖子:https://groups.google.com/forum/#!topic / phonegap/GKoTOSqD2kc

file.file(function(e) {
    console.log("called the file func on the file ob");
    var reader = new FileReader();
    reader.onloadend = function(evt) {
        app.log('onloadend');
        app.log(evt.target.result);
    };
    reader.readAsText(e);

});
Run Code Online (Sandbox Code Playgroud)