ASP.NET Core 7: Better file upload integration with Swagger on Minimal APIs


Uploading a/several file(s) was extremely easy with ASP.NET Core MVC and ASP.NET Core WebAPI. These framework provided interfaces IFormFile to upload a file and handle it server-side and IFormFileCollection to handle several files. Unfortunately before ASP.NET Core 7, these interfaces were not available on Minimal APIs and you had to fetch files into the HttpRequest.Forms object which disallowed you to upload file with Swagger. ASP.NET Core 7 fixes it and I will make you a little demo in this post.

Before ASP.NET Core 7

The old manner to post files was not really as efficient as we expected on Minimal APIs. Before ASP.NET Core 7 you had to upload your files as follow:

And it was not integrated at all with Swagger as you can see:

Since ASP.NET Core 7

IFormFile and IFormFileCollection are available and give the following code respectively:

And as you can see they are pretty integrated with Swagger:

Good news right ? 😉

Written by


Anthony is a specialist in Web technologies (14 years of experience), in particular Microsoft .NET and learns the Cloud Azure platform. He has received twice the Microsoft MVP award and he is also certified Microsoft MCSD and Azure Fundamentals.
%d bloggers like this: