The following CreateImages endpoint is in my C# .NET Web API. Testing with Postman and Swagger UI, when I upload files and send the request, files parameter below is always null. I don't have this issue if I update the parameter to a single IFormFile, it is only when I try to pass a list.
public class Images : EndpointGroupBase
{
public override void Map(WebApplication app)
{
app.MapGroup(this)
.DisableAntiforgery()
.RequireAuthorization()
.MapPost(CreateImages);
}
public async Task<IResult> CreateImages(ISender sender, [FromForm] IList<IFormFile> files)
{
return Results.Ok(await sender.Send(new CreateImagesCommand(files)));
}
}
I get the same issue with the following types: IList, List, ICollection, IEnumerable. If I pass an array (IFormFile[]), even with the [FromForm] tag, It will not be registered as multipart/form-data but expects a list of strings. I assume this is not recommended anyways. Also, as mentioned, if I update this endpoint to instead accept a single IFormFile, everything works as expected - value is not null and debugger can proceed with item as expected IFormFile type.
