4.17Adding IFormFile and IFormFileCollection content

Created on Aug 17, 2026~2 min read

In ASP.NET Core, the IFormFile interface is used to handle single file uploads, while the IFormFileCollection interface manages multiple file uploads. These two interfaces simplify the implementation of file upload functionality. The framework provides the AddFile(IFormFile) and AddFiles(IFormFileCollection) extension methods to make it easy to add files to multipart form content. Examples are as follows:

cs
HttpRequestBuilder.Post("https://furion.net")    .SetMultipartContent(multipart =>    {        multipart.AddFile(formFile);        multipart.AddFile(formFile, "file");    // Custom form name        multipart.AddFile(formFile, "file", "test.txt");    // Custom file name        multipart.AddFile(formFile, "file", "test.txt", "text/plain");    // Custom media type        multipart.AddFiles(formFiles);        multipart.AddFiles(formFiles, "files"); // Custom form name    });

Note: If IFormFile is used as the type of a model property, for example:

cs
public class FormClass // Supports the [AliasAs] attribute to define an alias{    public int Id { get; set; }    public string Name { get; set; }    public IFormFile File { get; set; }}

then you need to ensure that FormFileContentProcessor is registered. Registration can be done by calling .AddHttpContentProcessors(() => [new FormFileContentProcessor()]) globally or locally:

  • Per-request configuration:
cs
HttpRequestBuilder.Post("https://furion.net/")    .AddHttpContentProcessors(() => [ new FormFileContentProcessor() ])
  • Global configuration:

In the Startup.cs or Program.cs file, configure and register the HttpRemote service to enable the IFormFile content processor feature:

cs
services.AddHttpRemote(builder =>{    builder.AddHttpContentProcessors(() => [ new FormFileContentProcessor() ]);});