how to handle a multiple file upload request and [Object Filelist]?

Asked

Viewed 73 times

1

I’m trying to upload multiple files, but 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 executing 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--
No answers

Browser other questions tagged

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