Add file object to an array in file upload

Viewed 593

Want to send file object in array item along with other field. I am trying to achieve structure given in image,

please let me know if any suggestion.

upload multiple file structure image

the component is like this https://stackblitz.com/edit/angular-ivy-3hwcmv?file=src/app/app.component.ts

I selectAttachment() function, I am trying to put the file object in array element along with price.

I want to send the entire attachmentArray to back-end along with fileobject for each row whose file is selected.

1 Answers

Here, you get the FileList in your property attachmentArray

  selectAttachment(event, i) {
    const file: File = event.target.files[0];
    if (file) {
      const fileName = file.name;
      this.attachmentArray[i].fileName = fileName;
      this.attachmentArray[i].file = file;
    }
    console.log(event.target);
    console.log(this.attachmentArray); 
  }

When tried logging from uploadFile, it logs the sample object on actual browser consoleActual browser console Upload full log uploadFile res on stackblitz console

Related