我试图下载多个文件。文件在我的设备中下载正常。但是 progressEvent 给出了一些奇怪的结果。对于所有情况 progressEvent.total 返回 -1。尽管 progressEvent.loaded 值总是在变化。如何修复它。
function downloadFile(remoteUrl, localPath) {
var fileTransfer = new FileTransfer();
fileTransfer.onprogress = function(progressEvent) {
if (progressEvent.lengthComputable) {
var perc = Math.floor(progressEvent.loaded / progressEvent.total * 100);
//statusDom.innerHTML = perc + "% loaded...";
statusDom.innerHTML = progressEvent.loaded + " - " + progressEvent.total;
} else {
if(statusDom.innerHTML == "") {
statusDom.innerHTML = "Loading";
} else {
statusDom.innerHTML += ".";
}
}
};
fileTransfer.download(encodeURI(remoteUrl), localPath, function(e) {}, fail);
}