文件传输正在进行中不起作用 - PhoneGap 3.5.0

FileTransfer onprogress not working - PhoneGap 3.5.0

本文关键字:PhoneGap 不起作用 传输 进行中 文件      更新时间:2023-09-26
似乎

从未调用过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 函数定义中的参数变量。

它应该是:

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

希望对您有所帮助!