Angular + core 如何将文件数组从 Angular 上传到 Dot Net Core

Angular + core How to upload Array of file from Angular to Dot Net Core

这里正在获取要上传的文件数组。但我无法绑定我的数据

fileList: File[] = [];
listOfFiles: any[] = [];
 onFileChanged(event: any) {
    for (var i = 0; i <= event.target.files.length - 1; i++) {
      var selectedFile = event.target.files[i];
      this.fileList.push(selectedFile);
      this.listOfFiles.push(selectedFile.name)
  }
}

我在这里上传我的文件到服务器

upload() {
  const formData: any = new FormData();
formData.append('ofile',this.fileList)
  console.log('form data variable :   '+ formData.toString());
this._service.PostFormData(formData).subscribe(data=>{  
});
}

HTML代码

<input type="file" (change)="onFileChanged($event)">
<input type="file" (change)="onFileChanged($event)">
<input type="file" (change)="onFileChanged($event)">

<!-- <button mat-icon-button (click)="removeSelectedFile(index)">delete</button> -->
<button (click)="upload()">Save</button>

我正在使用的核心方面

    public class Test
    {
      //  public List<IFormFile> ofile { get; set; }
        public byte[] ofile { get; set; }
  }

控制器

[HttpPost]
    public IActionResult GetName([FromForm]Test oTest)
    {
      }

这里我得到的是空值请帮我解决这个问题

您应该foreach fileList 并将文件一一添加到formData。

upload() {
const formData: any = new FormData();
$.each(this.fileList, function (i, file) {
    formData.append('ofile', file);
});
this._service.PostFormData(formData).subscribe(data=>{  
});
}

型号:

public class Test
{
    public List<IFormFile> ofile { get; set; }
}