Reputation: 31
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
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.
Upvotes: 1
Reputation: 31
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);
}
select form-data in postman & send multiple files postman data input
Upvotes: 0
Reputation: 568
First, add your text in the Body->raw
Then go to Body->binary->Select file
Upvotes: 0