minimal-api-file-upload

Implements file upload endpoints in ASP.NET Core minimal APIs with validation and streaming.

Updated Aug 9, 2026
One-click install
npx skills add https://github.com/adinj00/player-performance --skill minimal-api-file-upload-adinj00
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: minimal-api-file-upload
Source: https://github.com/adinj00/player-performance/tree/main/.agents/skills/minimal-api-file-upload
Command: npx skills add https://github.com/adinj00/player-performance --skill minimal-api-file-upload-adinj00

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Building file upload endpoints in ASP.NET Core minimal APIs involves several non-obvious pitfalls: IFormFile binding rules, two separate size limits (Kestrel and FormOptions), automatic anti-forgery validation in .NET 8+, and security risks from trusting user-supplied filenames or content types. This Skill provides correct, production-oriented patterns for each of these concerns. ## Core Features & Use Cases - IFormFile Binding Patterns: Correctly bind single files, multiple files (IFormFileCollection), and mixed form fields using [FromForm] in minimal API endpoints. - Size Limit Configuration: Configure both Kestrel MaxRequestBodySize and FormOptions.MultipartBodyLengthLimit, plus per-endpoint overrides with RequestSizeLimit and DisableRequestSizeLimit. - Security Validation: Validate uploads via magic bytes instead of trusting Content-Type or file extensions, and prevent path traversal by generating safe filenames. - Large File Streaming: Use MultipartReader to stream large uploads directly to disk without buffering entire files in memory. - Use Case: You are building a .NET 8 API that accepts image uploads from a mobile client. Use this Skill to implement the endpoint with proper size limits, anti-forgery opt-out for JWT-authenticated APIs, and content-based file type verification. ## Quick Start Ask the AI to create a minimal API file upload endpoint in .NET 8 that accepts images with size limits and content validation.

Frequently Asked Questions about minimal-api-file-upload

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I upload files in ASP.NET Core minimal APIs?

In .NET 8+ minimal APIs, IFormFile binds automatically from multipart/form-data when it is the only complex parameter. When mixing files with other form fields, apply [FromForm] to all form-bound parameters or group them into a single [FromForm] DTO.

How do I upload multiple files with IFormFileCollection?

Use IFormFileCollection as the endpoint parameter, and it binds automatically from multipart/form-data. You only need [FromForm] if you mix the collection with other form fields in the same endpoint.

Why does my file upload fail with request too large in .NET?

There are two separate limits: Kestrel MaxRequestBodySize (default 30MB) and FormOptions.MultipartBodyLengthLimit (default 128MB). You must configure both, or use [RequestSizeLimit] per endpoint, otherwise the upload fails at whichever limit is hit first.

Why do I get 400 errors on file uploads in .NET 8?

In .NET 8+, UseAntiforgery() automatically validates anti-forgery tokens on all form-bound endpoints, including file uploads. For API-only endpoints, call .DisableAntiforgery(), which is safe for JWT or unauthenticated endpoints but not cookie-authenticated ones.

When should I use MultipartReader instead of IFormFile?

Use MultipartReader for very large files (over 1GB) where IFormFile's multipart parsing would buffer content in memory and spill to temp files. MultipartReader streams sections directly to storage in chunks without buffering the entire file.

How do I validate uploaded file types securely in ASP.NET?

Never trust the file extension or client-provided Content-Type alone, since both are spoofable. Check the file's magic bytes (e.g., FF D8 FF for JPEG, 89 50 4E 47 for PNG) and generate a safe filename with Guid.NewGuid() to prevent path traversal.