4.10Adding object content (complex forms / file uploads)

Created on Aug 17, 2026~5 min read

When you need to add an object to multipart form content, HttpMultipartFormDataBuilder provides flexible handling depending on whether a form name is specified.

1. No form name specified: In this case, the object is parsed and traversed, and its properties are set as individual form items.

cs
HttpRequestBuilder.Post("https://furion.net")    .SetMultipartContent(multipart =>    {        multipart.AddObject(new { id = 1, name = "furion" }); // No form name specified (will be assigned to the Id and Name properties of FormClass)    });

The above code will generate two form items: Id and Name, which correspond to the class definition received on the server side, such as:

cs
public class FormClass{    public int Id { get; set; }    public string Name { get; set; }    // other properties}

2. Form name specified: If a form name is specified for the object, the entire object is set as a nested item of the form. This is typically used when the server expects to receive an object with a nested structure.

cs
HttpRequestBuilder.Post("https://furion.net")    .SetMultipartContent(multipart =>    {        multipart.AddObject(new { id = 1, name = "furion" }); // No form name specified (will be assigned to the Id and Name properties of FormClass)        multipart.AddObject(new { id = 1, name = "furion" }, "child"); // Form name specified, will be assigned to the Child property of FormClass    });

In this case, the class definition received on the server side should include a nested class, such as:

cs
public class FormClass{    public int Id { get; set; }    public string Name { get; set; }    public ChildClass Child { get; set; } // nested class    // other properties...}public class ChildClass{    public int Id { get; set; }    public string Name { get; set; }    // other properties...}

Complex forms containing files (or binary data)

In addition to basic data types, object fields can also contain files or binary data (such as Stream, IFormFile, FileInfo, or MultipartFile). It is recommended to use the MultipartFile type to declare file fields.

The sample code is as follows:

cs
HttpRequestBuilder.Post("https://furion.net")    .SetMultipartContent(multipart =>    {        multipart.AddObject(new FormClass { Id = 1, Name = "furion", File = MultipartFile.CreateFromPath("file path") });    });

The corresponding model class definition is as follows:

cs
public class FormClass // Supports the [AliasAs] attribute to define aliases{    public int Id { get; set; }    public string Name { get; set; }    public MultipartFile File { get; set; }    // public IFormFile File { get; set; }  // Note: requires configuration following the steps below}

Note: If you use IFormFile instead of MultipartFile, you must ensure that FormFileContentProcessor is registered. Registration can be completed by calling .AddHttpContentProcessors(() => [new FormFileContentProcessor()]) globally or locally:

  • Single 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 functionality:

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