minimal-api-file-upload

Implement ASP.NET Core minimal API file upload endpoints with multipart handling.

1|Updated May 21, 2026
One-click install
npx skills add https://github.com/1k-off/umbraco-observability-playground --skill minimal-api-file-upload-1k-off
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: minimal-api-file-upload
Source: https://github.com/1k-off/umbraco-observability-playground/tree/main/.agents/skills/minimal-api-file-upload
Command: npx skills add https://github.com/1k-off/umbraco-observability-playground --skill minimal-api-file-upload-1k-off

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It helps you implement reliable file upload endpoints in ASP.NET Core minimal APIs while avoiding common failures and security pitfalls such as incorrect multipart binding, misconfigured size limits, CSRF issues, and unsafe path handling.

Core Features & Use Cases

  • Correct multipart binding: Bind IFormFile or IFormFileCollection in minimal APIs and handle mixed form fields using [FromForm].
  • Comprehensive size-limit control: Configure both Kestrel request limits and multipart/form limits, with per-endpoint overrides.
  • Safer upload handling: Prevent CSRF problems (anti-forgery defaults in .NET 8+) and mitigate file-based attacks by validating content via magic bytes and using safe filenames.
  • Streaming for large uploads: Use MultipartReader to process multipart data without buffering the entire upload.

Quick Start

Ask: "Generate a .NET 8 minimal API endpoint that accepts an uploaded image, validates it by MIME type and magic bytes, enforces correct request limits, and streams large uploads to disk safely."

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 using IFormFile?

To handle file uploads in ASP.NET Core minimal APIs, bind IFormFile or IFormFileCollection parameters and use [FromForm] for mixed multipart fields. This ensures correct multipart/form-data parsing and reliable request processing without manual extraction.

What's the best way to stream large file uploads in .NET 8 minimal APIs?

The best way to stream large file uploads is using MultipartReader to process multipart data without buffering the entire request in memory. This approach prevents memory exhaustion and enables reliable disk streaming for large files.

How do I configure request size limits for file uploads in ASP.NET Core minimal APIs?

Configure request size limits by adjusting both Kestrel request limits and FormOptions multipart/form limits. You can apply global limits and use per-endpoint overrides to safely handle different upload size requirements.

How do I prevent path traversal attacks when saving uploaded files in minimal APIs?

Prevent path traversal attacks by generating safe filenames instead of trusting user input. Additionally, validate file content via magic bytes rather than extensions alone to mitigate file-based attacks.

Do I need anti-forgery tokens for file upload endpoints in .NET 8 minimal APIs?

Yes, .NET 8+ enables anti-forgery defaults for minimal APIs to prevent CSRF problems. You need optional anti-forgery handling configured to secure multipart/form-data file upload endpoints against cross-site request forgery.