How to Create an API with Minimal APIs | Minimal API upload file

Описание к видео How to Create an API with Minimal APIs | Minimal API upload file

How to Create an API with Minimal APIs | Minimal API upload file
Swagger with minimal api? minimal api file upload not working with swagger? IFormFile not working with swagger.

you will get answers to all these questions if you watch this .Net6 Minimal Apis file upload video. I have demonstrated creating a minimal api using dotnet6 for file upload and added swagger support. Swagger file upload does not work with dotnet6 minimal api. Also, IFormfile does not work with dotnet6 minimal api. To upload file using minimal api, we have to use HttpRequest itself instead of using IFormFile like we do in regular asp.net core web api file upload. minimal apis is a cool feature added as part of dotnet6 and using them we can create an api with minimal code.
---------------------------------------------------------------
In this demo, we have created a dotnet6 minimal api endpoint which accepts multiple files via HttpRequest message. we can iterate over the file those were submitted to dotnet6 asp.net core web api/minimal api files and save them to the location that we want. After writing the code, if you run the application, it will not work as swagger for minimal apis does not support files. you will see the IFormFile as an array of string and we need to see file upload for minimal api.
------------------------------------------------------------
To mitigate the issue, we need to use IOperationFilter. This filter helps transforming the operation for swagger. In IOperationFilter for swagger, we need to define the schema for minimal api upload file swagger. we need to check for IFormFile type and in the schema, we need to use OpenApiSchema, OpenApiMediaType classes to define the schema. Once we make all the configuration and run the applicaiton, swagger for minimal apis will show you file uploads. we can add multiple files web api file upload.
Once the files are uploaded, we need to iterate over HttpRequest.Form.Files and save them to the drive.

Chapters
00:00 Intro
00:31 Creating .Net6 Minimal API Project
01:25 Defining .Net6 Minimal API File Upload Endpoint
06:02 Creating Swagger IOperationFilter
12:00 Testing Minimal Api File upload with Swagger

#DotNet6MinimalAPIFileUpload#
#MinimalAPIFileUpload#
#MinimalAPIFileUploadWithSwagger#

Комментарии

Информация по комментариям в разработке