Search code examples
c#asp.net-corepostmaniformfile

How create endpoint in asp.net core accepting multiple files with a text linked to each file?


I want to create a new endpoint in an existing asp.net core API. It should be possible to upload multiple files with a linked text string to each file. I also want to use PostMan to test this endpoint. Is it possible to do this?

This is my C# test code that runs but i don't know how to call it from PostMan:

    [HttpPost("upload/test")]
    public async Task<IActionResult> FileUpload([FromForm]UploadModel fileUpload)
    {
        return FileUpload(fileUpload);
    }
    public class UploadModel
    {
        /// <summary>
        /// Files to upload
        /// </summary>
        public List<FileModel> Files { get; set; }
        public string UploadInfo{ get; set; }
    }

    public class FileModel
    {
        public IFormFile File { get; set; }
        public string FileText { get; set; }
    }

Solution

  • For passing List Object from postman to api, you could try struct like parameterName[index].fieldName.

    Here is a demo which works for you. enter image description here