progressEvent.lengthComputable记录false值

时间:2017-08-15 16:36:33

标签: angular ionic2 cordova-plugins ionic3 ionic-native

我在离子3中使用离子本机fileTransfer来显示下载/上传文件时的进度..我似乎无法取得进展

.ts

download(attachment){
  const fileTransfer: TransferObject = this.transfer.create()

  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' when 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'
       }
    });
  });

  fileTransfer.download(url, this.storageDirectory + attachment.fileName, true).then((entry)=>{
    console.log('entry': entry);
  });
 }

0 个答案:

没有答案