liveBook · Manning

IFormFileCollection

As explained in ASP.NET Core in Action, 3e

IFormFileCollection is the ASP.NET Core collection type representing uploaded files received from a multipart form request.

IFormFileCollection represents multiple files uploaded with a request. ASP.NET Core can bind it directly to minimal API handlers or Razor Page handlers. section 7.6 section 16.2.2

Use IFormFileCollection when handling several uploaded files, while keeping these practical concerns in mind:

  • Iterate through the collection and use each IFormFile to read uploaded content. section 7.6.3
  • Treat filenames as untrusted input and generate a new name before saving a file. section 7.6.3
  • Expect buffering in memory and on disk; large uploads may require streaming, which is more complex and error-prone. section 7.6.3
  • Decide carefully whether uploaded data belongs in a database, filesystem, or another storage system. section 7.6.3

Binding several files in a minimal API

app.MapGet("/upload", (IFormFileCollection files) => { foreach (IFormFile file in files) { // Read or process each file here } });

app.MapGet("/upload", (IFormFileCollection files) =>
{
   foreach (IFormFile file in files)
   {
   }
});

Browse the minimal API example that receives an IFormFileCollection and iterates over its individual files. section 7.6.3

How ASP.NET Core in Action, 3e covers it

How deep it goes
Explains binding, iteration, buffering risks, filename safety, storage decisions, and defers large-file streaming.
Examples
Demonstrates a minimal API endpoint that receives a collection and iterates through each uploaded file.
What you can do after
Apply it via ASP.NET Core model binding to receive and process multiple uploaded files.
How it connects
Connects IFormFileCollection with IFormFile, model binding, minimal APIs, Razor Pages, file storage, and upload security.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ASP.NET Core in Action, 3e. The section links point to the parts of the book it draws on.