how to add a progress bar on uploading a file

前端 未结 1 1155
你的背包
你的背包 2021-01-15 06:00

i am transferring file to a url, i could do it successfully but i dont know how to get the progress of the file that is been uploaded, i need to get progress in some numbers

1条回答
  •  被撕碎了的回忆
    2021-01-15 06:22

    You can show progressBar by using onProgress function like this

    public   fileTransfer: TransferObject = this.transfer.create();
    public upload(path,folder) 
    {
      url="http://www.axmag.com/download/pdfurl-guide.pdf";
      var trustHosts = true;
      this.presentLoading("Loading");
      //**Progress Bar**
      this.fileTransfer.onProgress((e)=>
      {
        let prg=(e.lengthComputable) ?  Math.round(e.loaded / e.total * 100) : -1;  
        console.log("progress:"+prg);
      });
    
      this.fileTransfer.upload(file_path, api_endpoint, options, data).then((entry) => {
    //handle success        
    console.log('upload complete: ' );
      },
      (error) => {
        this.loader.dismiss();
        alert('uploading faild: ');
        console.log(error);
      //handle error
      });
    }
    

    Now you can call upload() function to upload a file

    0 讨论(0)
提交回复
热议问题