为什么在swagger中用minimalAPI上传IFormFile文件是空的?

问题描述 投票:0回答:1

我正在尝试使用 C# NetCore7 中的最小 API 编写一个 http 帖子,它接收 IFormFile 文件。

最小API:

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

当我使用swaggerUI上传文件时,文件为空:

我做错了什么?

swagger swashbuckle swashbuckle.aspnetcore minimal-apis asp.net-core-7.0
1个回答
0
投票

问题出在以下行:

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

当我删除以下

WithOpenAPi()
扩展时,上传文件正常工作!

© www.soinside.com 2019 - 2024. All rights reserved.