Anders
Anders

Reputation: 31

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

Upvotes: 0

Views: 1899

Answers (3)

Xueli Chen
Xueli Chen

Reputation: 12695

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

Upvotes: 1

Vinaykumar
Vinaykumar

Reputation: 31

  1. Modify controller method to accept multiple form Files as -

    [HttpPost("upload/test")]
    public async Task<IActionResult> FileUpload([FromForm] List<IFormFile> files)
    {
        return await UploadFile(files);
    }
    
  2. select form-data in postman & send multiple files postman data input

Upvotes: 0

Valeriu Seremet
Valeriu Seremet

Reputation: 568

First, add your text in the Body->raw

Then go to Body->binary->Select file

mroe info

enter image description here

Upvotes: 0

Related Questions