how to handle a multiple file upload request and [object FileList]?

1

I'm trying to upload with multiple files, however the request is sending a string: [object FileList]

<file 
  class="btn btn-default" 
  name="fotos_empreendimento" 
  accept=".jpeg,.png,.gif" 
  ng-model="vm.model.fotos_empreendimento" 
  multiple="multiple" 
 ng-change="vm.salvarFoto()">                   
</file>

Function that executes the request

salvarFoto() {
  const URL = this.model.id ? 
 '${this.host}/empreendimento/${this.empreendimentoId}/fotos' : 
 '${this.host}/empreendimento/${this.empreendimentoId}/fotos';

  this.$http({
    url: URL,
    method: 'POST',
    headers: {
     'Content-Type': 'multipart/form-data'
    },
    transformRequest: () => {
    const formData = new FormData();
    if (this.model.fotos_empreendimento) {
     formData.append('fotos_empreendimento', 
      this.model.fotos_empreendimento);
     }
    return formData;
    },
    data: {
    fotos_empreendimento: this.model.fotos_empreendimento
     }
    }).then(result => {
    if (!result.data.errors) {
      this.$state.go('empreendimento.upload_imagem', 
      {empreendimentoId: this.empreendimentoId}, {reload: true});
      this.$timeout(() => {
      }, 500);
     }
 });
}

How it was sent

------WebKitFormBoundaryIWTEU2c0n30RrbfA
Content-Disposition: form-data; name="fotos_empreendimento"

[object FileList]
------WebKitFormBoundaryIWTEU2c0n30RrbfA--
    
asked by anonymous 06.12.2018 / 13:31

0 answers