I cannot seem to get progress value
.ts
download(attachment){
const fileTransfer: TransferObject = this.transfer.create();
this.platform.ready().then(() => {
if (this.platform.is('ios')) {
this.storageDirectory = this.file.documentsDirectory;
}
else if (this.platform.is('android')) {
this.storageDirectory = this.file.externalRootDirectory+ '/Download/';
} else {
return false;
}
this.is_downloading = true; // show progressBar
fileTransfer.onProgress((progressEvent: ProgressEvent) => {
this.ng_zone.run(() => {
console.log('progressEvent.lengthComputable: ', progressEvent.lengthComputable)
// SHOWS FALSE
if (progressEvent.lengthComputable){
console.log('progressEvent.loaded: ', progressEvent.loaded)
// if condition removed, .loaded seems fine showing value
console.log('progressEvent.total: ', progressEvent.total)
// no total , showing '0'
let progress = Math.round((progressEvent.loaded / progressEvent.total) * 100);
if (progress > 100) progress = 100;
if (progress < 0) progress = 0;
this.progress = progress;
console.log('progress : ', progress);
// 'Infinity'
}
});
});
const url = 'some url';
let trustAllHosts = true;
fileTransfer.download(url, this.storageDirectory + attachment.fileName, trustAllHosts).then((entry)=> {
const alertSuccess = this.alertCtrl.create({
title: 'Download Succeeded',
subTitle : attachment.fileName + ' was successfully downloaded to '+ entry.toURL(),
buttons: ['Ok']
});
alertSuccess.present();
}, (err) => {
const alertFailure = this.alertCtrl.create({
title: 'Download Failed',
subTitle: attachment.fileName + ' was not successfully downloaded. Error code: '+ err,
buttons: ['Ok']
});
alertFailure.present();
});
});
.html
<div *ngIf="is_downloading">
<span>File</span>
<progress-bar [progress]="progress"></progress-bar>
</div>