Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 30, 2025

Fixes #[issue-number]

Summary

This PR adds clarification to the minimal APIs documentation regarding IFormFile binding requirements in response to user feedback indicating confusion about whether form encoding is required or if the entire request body can be interpreted as the file.

Problem

Users were unclear about the requirements for using IFormFile in minimal APIs, specifically:

  • Whether multipart/form-data encoding is mandatory
  • Whether the entire request body can be bound directly to an IFormFile parameter
  • How parameter names relate to form field names

Changes

Added explicit clarification to the "File uploads using IFormFile and IFormFileCollection" section across all version-specific parameter binding documentation files (versions 7, 8, 9, and 10):

Added text:

File uploads using IFormFile and IFormFileCollection in minimal APIs require multipart/form-data encoding. The parameter name in the route handler must match the form field name in the request. Minimal APIs don't support binding the entire request body directly to an IFormFile parameter without form encoding.

This clarification is placed immediately before the code example to ensure developers understand the requirements before implementing file uploads.

Files Modified

  • aspnetcore/fundamentals/minimal-apis.md - Updated ms.date to 09/30/2025
  • aspnetcore/fundamentals/minimal-apis/includes/parameter-binding7.md
  • aspnetcore/fundamentals/minimal-apis/includes/parameter-binding8.md
  • aspnetcore/fundamentals/minimal-apis/includes/parameter-binding9.md
  • aspnetcore/fundamentals/minimal-apis/includes/parameter-binding10.md

Validation

  • Markdown lint validation passed with no new errors introduced
  • Changes are minimal and surgical (9 insertions, 1 deletion across 5 files)
  • Consistent implementation across all ASP.NET Core version files
Original prompt

This section details on the original issue you should resolve

<issue_title>UUF: Minimal-APIs: Add IFormFile binding information</issue_title>
<issue_description>### 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)</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>
Fixes #36060

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] UUF: Minimal-APIs: Add IFormFile binding information Add IFormFile binding information to minimal APIs documentation Sep 30, 2025
@Copilot Copilot AI requested a review from wadepickett September 30, 2025 22:06
Copilot finished work on behalf of wadepickett September 30, 2025 22:06
@tdykstra tdykstra added the reQUEST Triggers an issue to be imported into Quest label Sep 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
reQUEST Triggers an issue to be imported into Quest
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UUF: Minimal-APIs: Add IFormFile binding information
3 participants