【问题标题】:Add file object to an array in file upload在文件上传中将文件对象添加到数组
【发布时间】:2021-08-01 12:44:39
【问题描述】:

想要将数组项中的文件对象与其他字段一起发送。我正在尝试实现图像中给出的结构,

如果有请告诉我 任何建议。

upload multiple file structure image

组件是这样的https://stackblitz.com/edit/angular-ivy-3hwcmv?file=src/app/app.component.ts

我选择附件()函数,我试图将 文件对象 与价格一起放入数组元素中。

我想将整个 attachmentArray 连同文件对象一起发送到后端,以选择文件被选中的每一行。

【问题讨论】:

    标签: angular file-upload


    【解决方案1】:

    在这里,您可以在您的财产attachmentArray 中获得FileList

      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); 
      }
    

    当尝试从uploadFile 记录时,它会在实际浏览器控制台 上记录示例对象

    【讨论】:

      猜你喜欢
      • 2017-07-14
      • 2015-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-06
      • 2019-06-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多