Back to Blog

automation

File Uploads in Minimal APIs: A Practical Agent Skill

Add a practical skill to your agent toolkit for building validated file upload endpoints in ASP.NET Core minimal APIs.

OpenAgentSkillPublished:

Where this fits

A developer is extending a .NET 8 service with a document upload feature. They wire an IFormFile parameter into a minimal API endpoint, and it works locally—then production rejects large PDFs and accepts disallowed content types. This skill captures the binding rules, validation patterns, and size-limit setup that usually live scattered across docs and Stack Overflow.

Why agents benefit

  • Can generate correct minimal API upload endpoints with IFormFile or IFormFileCollection, including [FromForm] disambiguation when mixed with other fields.
  • Applies request and file size limits without guessing: MaxRequestBodySize, MultipartBodyLengthLimit, and per-endpoint overrides.
  • Adds content-type/extension validation at the endpoint boundary, reducing the chance of accepting arbitrary files.
  • Knows when to switch to MultipartReader streaming for large files, preventing memory exhaustion.
  • Produces a concrete checklist: enforce limits, validate allowed types, return problem details, then persist.

Practical scenarios

Adding a single-file upload endpoint

The agent is asked to create POST /upload that accepts a resume PDF. It can generate the endpoint with an IFormFile parameter, set a 10 MB limit, validate application/pdf, and return a file ID.

Handling multiple files in one request

For a batch image upload, the skill maps IFormFileCollection and loops through files while validating each extension. It also handles the .NET 8 binding quirk: when the endpoint has other complex parameters, the agent knows to use [FromForm] explicitly.

Protecting streaming uploads

When the client sends video files up to 500 MB, the agent can switch to MultipartReader to avoid buffering in memory. It then writes chunks to disk or object storage with steady progress reporting.

Add it to your agent workflow

Install the skill from the managedcode/dotnet-skills repo:

npx skills add managedcode/dotnet-skills --skill minimal-api-file-upload

Example agent request after install: "Create a minimal API endpoint for CSV upload, max 5 MB, only text/csv."

The skill returns:

app.MapPost("/upload-csv", async (IFormFile file, IConfiguration config) =>
{
    var maxBytes = config.GetValue<long>("Upload:MaxBytes", 5 * 1024 * 1024);
    if (file.Length == 0 || file.Length > maxBytes)
        return Results.BadRequest("Invalid file size");
    if (!file.ContentType.Equals("text/csv", StringComparison.OrdinalIgnoreCase))
        return Results.UnsupportedMediaType();
    // stream + persist
    return Results.Ok(new { Name = file.FileName });
});

Vary the generated code with your project's validation and storage conventions.

Compare before adopting

Before making this a default, compare these signals: check repository freshness and .NET 8+ alignment; verify the skill's file-size guidance matches your infrastructure; consider alternatives like a manually written prompt or a different minimal API skill; and assess workflow fit—does the agent actually need upload handling often enough to justify the dependency?

Why it is worth tracking

With 477 stars and an MIT license, this skill is a reasonable community signal, but the real value is momentum: .NET minimal APIs keep evolving, and upload handling rules change with each runtime. Track the repo for updates that align with current .NET versions and known binding issues. See the detailed skill page at https://www.openagentskill.com/skills/managedcode-minimal-api-file-upload to compare it with related ASP.NET Core skills.

Featured Skill

minimal-api-file-upload

Skill by managedcode