test_file([FromForm] IEnumerable lstFile) { r" /> test_file([FromForm] IEnumerable lstFile) { r" /> test_file([FromForm] IEnumerable lstFile) { r"/>

index0errorValue must be a string - Upload multiple files Swagger .NET 6.0

887 Views Asked by At

I declared a list IFormFile:

[HttpPost]
    [Route("test_file")]
    public async Task<IActionResult> test_file([FromForm] IEnumerable<IFormFile> lstFile)
    {
        return null;
    }

But swagger interpreted as a list of string and shows issue: "index0errorValue must be a string"(https://i.stack.imgur.com/9uaP1.png)

Can you help to fix this problem? Thanks a lot

EDIT: I fixed the error.

app.UseSwagger(options =>
{
//options.SerializeAsV2 = true;
options.RouteTemplate = swaggerOption.JsonRoute;
});

SerializeAsV2. I don't know how it works, but when I turned it off, it works.

1

There are 1 best solutions below

3
Reza Heidari On

You can use Consume attribute for that matter. The [Consumes] attribute in ASP.NET Core is used to specify the content types that a controller action method can consume or accept from which swagger is going to detect automatically.

[HttpPost]
[Consumes("multipart/form-data")]
[Route("test_file")]
public async Task<IActionResult> test_file([FromForm] IEnumerable<IFormFile> lstFile)
{
    // TODO: Apply the logic here 
    return null;
}

For more information you can check the documentation here