Skip to content

UUF: Minimal-APIs: Add IFormFile binding information #36060

@wadepickett

Description

@wadepickett

Description

Add IFormFile binding information to minimal APIs documentation

User feedback transferred from UUF System:

"IFormFile does not specify if the caller MUST use form encoding, or if simply interprets the entire body as the file"

The following Problem/Solution is just an AI generated recommendation and should be treated as such:

Problem Statement

The minimal APIs documentation currently does not include information about using IFormFile for file uploads. Specifically, it lacks details about whether form encoding is required when using IFormFile or if the entire request body can be interpreted as the file. This is important information for developers implementing file upload functionality in minimal APIs.

Proposed Solution

Add a section about file uploads with IFormFile to the parameter binding section of the minimal APIs documentation. This section should clarify:

  1. That multipart/form-data encoding is required when using IFormFile
  2. The supported request formats and parameter binding patterns
  3. Examples of implementing file uploads in minimal API endpoints

Suggested Changes

Add the following content to the Parameter binding section around line 153 (after the parameter binding include directive):

File uploads with IFormFile

When using IFormFile in minimal APIs, the following requirements and formats apply:

Request format requirements:

  • Form encoding is required: Requests must use multipart/form-data encoding when uploading files with IFormFile
  • The parameter name in your endpoint must match the form field name in the request
  • Unlike controller-based APIs, minimal APIs do not support binding the entire request body directly to an IFormFile parameter

Example implementations:

Single file upload:
app.MapPost("/upload", async (IFormFile file) =>
{
    var tempFile = Path.GetTempFileName();
    using var stream = File.OpenWrite(tempFile);
    await file.CopyToAsync(stream);
    
    return Results.Ok(new { 
        FileName = file.FileName,
        Length = file.Length,
        TempPath = tempFile
    });
});

### Page URL

https://learn.microsoft.com/en-us/aspnet/core/fundamentals/minimal-apis?view=aspnetcore-9.0

### Content source URL

https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/fundamentals/minimal-apis.md

### Document ID

b09824ab-b051-75a1-13b7-b0e281cc46e0

### Platform Id

24c01f0e-630a-08a5-698d-9668e1a7b40e

### Article author

@wadepickett

### Metadata

* ID: b09824ab-b051-75a1-13b7-b0e281cc46e0
* PlatformId: 24c01f0e-630a-08a5-698d-9668e1a7b40e 
* Service: **aspnet-core**
* Sub-service: **fundamentals**

[Related Issues](https://github.com/dotnet/AspNetCore.Docs/issues?q=is%3Aissue+is%3Aopen+b09824ab-b051-75a1-13b7-b0e281cc46e0)

---
[Associated WorkItem - 494560](https://dev.azure.com/msft-skilling/Content/_workitems/edit/494560)

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions