minimal-api-file-upload

Solid

File upload endpoints in ASP.NET minimal APIs (.NET 8+)

Data & Documents 3,357 stars 247 forks Updated today MIT

Install

View on GitHub

Quality Score: 93/100

Stars 20%
100
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# Implementing File Uploads in ASP.NET Core Minimal APIs ## When to Use - File upload endpoints in ASP.NET Core minimal APIs (.NET 8+) - Handling IFormFile or IFormFileCollection parameters - When you need size limits, content type validation, or streaming large files ## When Not to Use - MVC controllers → `[FromForm] IFormFile` works directly with attributes - Simple JSON body → no file upload needed - Very large files (> 1GB) → use streaming with `MultipartReader` instead ## Inputs | Input | Required | Description | |-------|----------|-------------| | File parameter(s) | Yes | IFormFile or IFormFileCollection | | Size limits | Yes | Max file/request size | | Allowed types | No | Content type or extension restrictions | ## Workflow ### Step 1: CRITICAL — Understand IFormFile Binding in Minimal APIs ```csharp // In .NET 8+ minimal APIs, IFormFile binds automatically from multipart/form-data // when it is the only complex parameter. app.MapPost("/upload", (IFormFile file) => ...); // CRITICAL: When you mix files with other form fields, use [FromForm] on all // form-bound parameters (or group them into a single [FromForm] DTO). app.MapPost("/upload-with-metadata", ([FromForm] IFormFile file, [FromForm] string description) => { return Results.Ok(new { file.FileName, Description = description }); }); // Multiple files: IFormFileCollection also binds automatically from multipart/form-data. // You only need [FromForm] if you mix it with other form fields, as shown...

Details

Author
dotnet
Repository
dotnet/skills
Created
4 months ago
Last Updated
today
Language
C#
License
MIT

Similar Skills

Semantically similar based on skill content — not just same category