Search code examples
javascriptasp.net-coremultipartform-dataaurelia

How to upload files with additional file data in asp.net core


I am trying to upload multiple files (documents) with additional data per file. Ie. I would like to upload multiple documents like this:

[{
  documentFile: file
  documentVersion: 2,
  documentOperation: "createNew"
  ...
 },
 {
  documentFile: file2.doc
  documentVersion: 1,
  documentOperation: "createNew"
  ...
 }]

And ideally would like that information to be populated in the model but this is not a requirement.

I am using Aurelia Fetch client to send data using FormData.

Is this possible?


Solution

  • If your model is like:

    public class Documents
    {
        public IFormFile documentFile { get; set; }
        public string documentVersion { get; set; }
        public string documentOperation { get; set; }
    }
    

    You can see my test.

    Action:

     [HttpPost]
        public IActionResult Demo(List<Documents> documents)
        {
            //...
        }
    

    Send data by postman:

    enter image description here

    Result:

    enter image description here