onprogress事件处理程序似乎从未被调用。成功回调正常进行,下载成功。我在这里做错什么了吗?

filesystem.root.getFile('/path/to/file', { create: true }, function (file) {

    var transfer = new FileTransfer();

    transfer.onprogress = function () {
        console.log(arguments);
    };

    transfer.download(
        'http://example.com/path/to/file',
        file.toURL(),
        function () { console.log('success'); },
        function () { console.log('error'); },
        true
    );

}, function () { console.log('error'); });


该应用程序使用带最新文件和文件传输插件的PhoneGap 3.5.0。我正在使用iOS 8的iPad上进行测试。

最佳答案

您似乎在onprogress函数定义上缺少arguments变量。

它应该是:

transfer.onprogress = function (progressEvent) {
    console.log(progressEvent);
    console.log(progressEvent.loaded); //Loaded bytes
    console.log(progressEvent.total); //Total bytes
    console.log(progressEvent.lengthComputable); //TRUE if the destination server informs total file length
};


您可以在这里找到文档:http://docs.phonegap.com/en/edge/cordova_file_file.md.html#FileTransfer

希望能帮助到你!

关于javascript - FileTransfer onprogress不起作用-PhoneGap 3.5.0,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26026384/

10-09 18:13