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 - 文件传输 onprogress 不起作用 - PhoneGap 3.5.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26026384/