# Individual progress bar for each submission

**URL:** <https://forum.ionicframework.com/t/individual-progress-bar-for-each-submission/203644>\
**Category:** Ionic Native\
**Created:** [January 27, 2021, 12:44pm UTC](https://forum.ionicframework.com/t/individual-progress-bar-for-each-submission/203644 "2021-01-27T12:44:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![HerickRaposo](https://avatars.discourse-cdn.com/v4/letter/h/5e9695/32.png) [@HerickRaposo](https://forum.ionicframework.com/u/HerickRaposo)\
**Post date:** [January 27, 2021, 12:44pm UTC](https://forum.ionicframework.com/t/individual-progress-bar-for-each-submission/203644/1 "2021-01-27T12:44:08Z")

</div>

Today I can upload files by displaying a progress bar. when I make a new request the values ​​of the progress bar are alternating between the values ​​of each shipment. In this way, I would like to show the progress bar individually for each document that is being sent, being able to add the description and the progress bar of the respective submission to the layout.

**HTML:**

```auto
<ion-item *ngIf="aux != 0">
    <ion-text >{{aux}}% </ion-text>
    <ion-label class="porcentagem"><ion-progress-bar [value]="porcentagem"></ion-progress-bar></ion-label>
    <ion-button color="danger" (click)="cancelarEnvio()">Cancelar</ion-button>
  </ion-item>

```

**Page:**

```auto
 ngOnInit() {
    this.apiService.getPorcentagemObservable().subscribe(res => {
      console.log('Novo Valor: ', res)
      
      if(res == 1){
        this.porcentagem = res / 100
        this.aux = res
      } else if (res == 100) {
        this.porcentagem = 0
        this.aux = 0
        this.changeDetectorRef.detectChanges()
      } else {
        this.porcentagem = res / 100
        this.aux = res
        this.changeDetectorRef.detectChanges() 
      }
    })
  }

```

**Service:**

```auto
import { Camera, CameraOptions, MediaType } from '@ionic-native/camera/ngx';
import { Injectable } from '@angular/core';
import { HTTP } from '@ionic-native/http/ngx';
import { FileTransfer, FileTransferObject, FileUploadOptions } from '@ionic-native/file-transfer/ngx';
import { BehaviorSubject, Observable } from 'rxjs';

@Injectable({
  providedIn: 'root'
})
export class ApiService {

  fileTransfer: FileTransferObject = this.transfer.create();
  private porcentagem = new BehaviorSubject(0)
  usuario:any   
  codigo:any

//=============================================> Construtor <=========================================

  constructor
  ( 
    private http: HTTP,
    private transfer : FileTransfer,

  ) {}

  salvarMalote(payload){
    console.log(payload)
    
    var filePath = payload.imageURI;
    var filename = filePath.split("/").pop();
    var extencao = filename.split(".").pop();
    let server
    var options : FileUploadOptions;

    let url //My url
    server = url 
    options = {
        fileKey: "file",
        fileName: filename,
        chunkedMode: false,

        headers: {
            Connecection: "close"
        },
        params: {
            Codigo: this.codigo,
            descricao: payload.descricao,
            email: this.usuario
        }
    }

 
    //Verificação de progresso 

    this.fileTransfer.onProgress((progressEvent) => {
      let perc
      if (progressEvent.lengthComputable) {
        perc = Math.floor((progressEvent.loaded / progressEvent.total) * 100);
        this.setPorcentagem(perc)
      } else {
        perc ++
      }
    });

    //upload

    console.log(filePath, server, options)
    return this.fileTransfer.upload(filePath, server, options).then((data) =>{
      let retorno = JSON.parse(data.response)
      console.log(retorno)
      if (retorno.sucesso) {
        this.setPorcentagem(100)
      } else {
        console.log('erro')
      }
      console.log()
    }, (error) => {
      console.log(error)
    });
  }

  //Metodos Observable

  setPorcentagem(perc){
    if (perc == 100) {
      this.porcentagem.next(0)
    } else{
      this.porcentagem.next(perc)
    }
  }

  getconst(): number {
    return this.porcentagem.getValue()
  }
  
  getPorcentagemObservable():Observable<number>{
    return this.porcentagem.asObservable()
  }

  abortar(){
    this.porcentagem.next(0)
    this.fileTransfer.abort()
  }

}

```

**Expected result:**  
 ![resultado](https://global.discourse-cdn.com/ionicframework/original/3X/7/c/7c212a6d7dfd5fed7fa8280fdcdb87bf7580c7f0.png)

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [January 27, 2021, 9:18pm UTC](https://forum.ionicframework.com/t/individual-progress-bar-for-each-submission/203644/2 "2021-01-27T21:18:43Z")

</div>

Personally, I would replace both the cordova HTTP and file transfer plugins with ordinary Angular `HttpClient`, but that’s tangential. You have but one notion of “progress” in your service, whereas you need to have one per request.

---

<div class="post-metadata">

**Author:** ![HerickRaposo](https://avatars.discourse-cdn.com/v4/letter/h/5e9695/32.png) [@HerickRaposo](https://forum.ionicframework.com/u/HerickRaposo)\
**Post date:** [January 28, 2021, 5:27pm UTC](https://forum.ionicframework.com/t/individual-progress-bar-for-each-submission/203644/3 "2021-01-28T17:27:11Z")

</div>

How can i do ito have one per request??

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [January 28, 2021, 7:34pm UTC](https://forum.ionicframework.com/t/individual-progress-bar-for-each-submission/203644/4 "2021-01-28T19:34:09Z")

</div>

You could have parallel lists, or you could add the progress level to your existing transaction object.
