Rename Arq with multiple upload

Asked

Viewed 24 times

1

I have a form that contains a file type input, where I need to send several Arq at the same time:

<div class="row p-3 hours_week" *ngFor="let subType of finalResultTotal">

      <input type="file" ng2FileSelect [uploader]="uploader" multiple id="{{subType}}SlotsInput"
                  [name]="subType.DATA_DIA+uploadHtml" class="text-light" (change)="inputFileChange($event)" multiple
                  ngModel #inpt="ngModel" #inpt="ngModel">
</div>

in ts I do so:

  public uploader: FileUploader = new FileUploader({
    isHTML5: true
  });

...

  constructor(){}

...

    onSubmit(form) {

          for (var j = 0; j < this.uploader.queue.length; j++) {
              this.enviaFoto = new FormData();

              this.fileItem = this.uploader.queue[j]._file;

       this.enviaFoto.append('photo', this.fileItem, this.fileItem.name);
      this.enviaFoto.append('fileSeq', 'seq' + j);
      this.uploadFile(this.enviaFoto).subscribe(data => 
           }
    this.uploader.clearQueue();
    }


  uploadFile(data: FormData): Observable<any> {

    return this.http.post<any>('http://localhost:3000/novaphoto', data);
  }

The Arq are inserted in my api all good, but then I need to change the name of the Arq before sending, and I did the following:

onsubmit(form) {

  for (var j = 0; j < this.uploader.queue.length; j++) {
      this.enviaFoto = new FormData();

      this.fileItem = this.uploader.queue[j]._file;


    if (this.day3.DIA === this.finalResultTotal[0].DATA_DIA) {
      this.day3.HORA = this.finalResultTotal[0].HORAS
      this.day3.SOBRA = this.finalResultTotal[0].TOTAL

      this.Day1Final = this.day3


    } else {

    }

    if (this.day3.DIA === this.finalResultTotal[1].DATA_DIA) {
      this.day3.HORA = this.finalResultTotal[1].HORAS
      this.day3.SOBRA = this.finalResultTotal[1].TOTAL

      this.Day2Final = this.day3

    } else {

    }

...

 if (this.Day1Final.UPLOAD) {

      Object.defineProperty(this.fileItem, 'name', {
        writable: true,
        value: (this.Day1Final.DIA).trim()
      });
      this.enviaFoto.append('photo', this.fileItem, this.fileItem.name);
      this.enviaFoto.append('fileSeq', 'seq' + j);
      this.uploadFile(this.enviaFoto).subscribe(data => console.log(data.message));
    }

    if (this.Day2Final.UPLOAD) {
      let foto = new FormData()
      Object.defineProperty(this.fileItem, 'name', {
        writable: true,
        value: (this.Day2Final.DIA).trim()
      });
      foto.append('photo', this.fileItem, this.fileItem.name);
      foto.append('fileSeq', 'seq' + j);
      this.uploadFile(foto).subscribe(data => console.log(data.message));

    }

       }
this.uploader.clearQueue();
}

If this.Day1final.UPLOAD is true, it means that there are some files in this array, such as Day2final.

Send to the api and is successfully sent, name the way I want, but will not the different photos, it is sending the same photo only with different names.

Could you help me?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.