0

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

3 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

First, add your text in the Body->raw

Then go to Body->binary->Select file

mroe info

enter image description here

1 Comment

It don't work for me when I try it this way. The raw body is: { "files" : [ { "filetext":"My text" } ], "uploadinfo":"Upload info text" }
0
  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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.