Search code examples
swaggerswashbuckleswashbuckle.aspnetcoreasp.net-core-7.0asp.net-minimal-apis

When uploading IFormFile file with minimalAPI in swagger, the file is null


I'm trying to write a http post using minimal API in C# NetCore7, that recieves IFormFile file.

MinimalAPI:

 var group = app.MapGroup("Payment").WithTags("Payment").WithOpenApi();
group.MapPost("htmlToPdf", async (IFormFile file) =>
    {
       ....
       ...       
}).Accepts<IFormFile>("multipart/form-data");

When I upload the file by using swaggerUI, the file is null:

SwaggerUI

What am I doing wrong?


Solution

  • The problem was in the following line:

    var group = app.MapGroup("Payment").WithTags("Payment").WithOpenApi();
    

    When i removed the following WithOpenAPi() extension, The uploading file is work properlly!