minimal-api-file-upload

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

1|Updated Jun 1, 2026
One-click install
npx skills add https://github.com/D1ssolve/craft-agents --skill minimal-api-file-upload-d1ssolve
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: minimal-api-file-upload
Source: https://github.com/D1ssolve/craft-agents/tree/main/skills/minimal-api-file-upload
Command: npx skills add https://github.com/D1ssolve/craft-agents --skill minimal-api-file-upload-d1ssolve

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-provided filenames or content types. This Skill provides correct, production-oriented patterns to avoid these common mistakes. ## Core Features & Use Cases - IFormFile Binding: 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 or DisableRequestSizeLimit. - Security Validation: Validate uploads via magic bytes instead of trusting Content-Type or file extensions, and generate safe filenames to prevent path traversal attacks. - Large File Streaming: Use MultipartReader to stream very large files directly to storage without buffering. - Use Case: You are building a .NET 8 API that accepts profile image uploads. Use this Skill to create an endpoint that enforces a 10 MB limit, verifies JPEG/PNG magic bytes, disables anti-forgery for JWT-authenticated clients, and saves files with GUID-based names. ## Quick Start Ask the AI to create a minimal API file upload endpoint in .NET 8 that accepts images, enforces size limits, validates file content, and protects against path traversal.

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, which 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 return 400 Bad Request 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.

Why does my large file upload fail even after increasing the size limit?

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 (over 1GB) where IFormFile's multipart parsing would buffer content in memory or 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 Core?

Never trust the file extension or Content-Type header alone, since both are client-spoofable. Read the file's magic bytes to detect the actual type, verify it matches the declared Content-Type, and generate a safe GUID-based filename to prevent path traversal.