minimal-api-file-upload

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

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? File uploads in ASP.NET Core minimal APIs fail in non-obvious 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 or content types. This Skill provides correct, production-oriented patterns for handling IFormFile binding, size limits, validation, and streaming. ## Core Features & Use Cases - Correct IFormFile Binding: Shows when IFormFile and IFormFileCollection bind automatically and when [FromForm] attributes are required for mixed form fields. - 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 or Content-Type headers, 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 that accepts image uploads and keeps getting 400 errors or oversized-request failures; this Skill walks you through anti-forgery opt-out, size limits, and content validation step by step. ## Quick Start Ask the AI to implement a secure file upload endpoint in an ASP.NET Core minimal API with size limits and content type 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 [FromForm] DTO.

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-only endpoints, call .DisableAntiforgery(), which is safe for JWT or unauthenticated endpoints but not cookie-authenticated ones.

How do I increase the file upload size limit in ASP.NET Core?▼

You must configure two separate limits: Kestrel's MaxRequestBodySize (default 30MB) and FormOptions.MultipartBodyLengthLimit (default 128MB). Setting only one causes uploads to fail at the other layer; use [RequestSizeLimit] for per-endpoint overrides.

Should I use IFormFile or MultipartReader for large file uploads?▼

IFormFile relies on multipart parsing that buffers content in memory and spills to temp files, making it unsuitable for very large files. Use MultipartReader to stream sections directly to storage in chunks without buffering the entire file.

How do I validate uploaded file types securely?▼

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