minimal-api-file-upload

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

Updated Jul 2, 2026
One-click install
npx skills add https://github.com/ecoDriverltd/FoundryAgentsExperiment --skill minimal-api-file-upload-ecodriverltd
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: minimal-api-file-upload
Source: https://github.com/ecoDriverltd/FoundryAgentsExperiment/tree/main/.agents/skills/minimal-api-file-upload
Command: npx skills add https://github.com/ecoDriverltd/FoundryAgentsExperiment --skill minimal-api-file-upload-ecodriverltd

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? File uploads in ASP.NET Core minimal APIs fail in confusing ways: mismatched size limits between Kestrel and form options, unexpected 400 errors from automatic anti-forgery validation, and security holes from trusting user-supplied filenames and content types. This Skill provides correct, production-aware patterns for handling IFormFile binding, size limits, validation, and large-file streaming. ## Core Features & Use Cases - Correct IFormFile Binding: Shows how IFormFile and IFormFileCollection bind from multipart/form-data, including when [FromForm] attributes are required. - Dual Size Limit Configuration: Configures both Kestrel MaxRequestBodySize and FormOptions.MultipartBodyLengthLimit, plus per-endpoint overrides with RequestSizeLimit. - Secure Validation: Validates file content via magic bytes instead of trusting extensions, and generates safe filenames to prevent path traversal. - Large File Streaming: Uses MultipartReader to stream large uploads directly to disk without buffering. - Use Case: You are building a .NET 8 API endpoint that accepts image uploads and keep getting 400 errors; this Skill identifies the anti-forgery cause and shows the correct DisableAntiforgery pattern. ## Quick Start Use the minimal-api-file-upload skill to create a secure file upload endpoint in my ASP.NET Core minimal API with a 10 MB size limit and JPEG/PNG 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 handle file uploads 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 DTO.

How do I upload multiple files with IFormFileCollection?▼

IFormFileCollection binds automatically from multipart/form-data in minimal APIs, so app.MapPost with an IFormFileCollection parameter works directly. You only need [FromForm] attributes when combining the collection with other form fields.

Why does my file upload return 400 Bad Request in .NET 8?▼

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

Why does my large file upload fail even after increasing Kestrel limits?▼

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.

When should I use MultipartReader instead of IFormFile?▼

Use MultipartReader for very large files where IFormFile's multipart parsing would buffer content in memory and spill to temp files. MultipartReader streams sections directly to storage in chunks, avoiding the buffering overhead.

Is it safe to save uploaded files using the user-provided filename?▼

No, user-provided filenames can contain path traversal sequences like ../../../etc/passwd. Generate a safe filename with Guid.NewGuid(), derive the extension from validated magic bytes, and verify content type against the declared ContentType header.