6.25The HttpFileUploadBuilder Builder

Created on Aug 17, 2026~2 min read

In addition to the above methods, you can also use the HttpFileUploadBuilder builder to configure the various settings required for uploading file resources.

cs
await httpRemoteService.SendAsync(HttpRequestBuilder.UploadFile("https://localhost:7044/HttpRemote/AddFile", @"C:\Workspaces\httptest.jpg", "file");

The HttpFileUploadBuilder builder is provided by the framework specifically to configure the various settings required for uploading file resources. The constructor of HttpFileUploadBuilder is private, so it cannot be instantiated directly with the new keyword; however, the framework provides several static overloads of HttpRequestBuilder.UploadFile to create an instance of HttpFileUploadBuilder.

cs
HttpRequestBuilder.UploadFile(httpMethod, requestUri, filePath, name, onProgressChanged, fileName, configure);HttpRequestBuilder.UploadFile(requestUri, filePath, name, onProgressChanged, fileName, configure); // Defaults to a POST request

In addition, HttpFileUploadBuilder includes the following configuration capabilities:

cs
// Defaults to a POST request, with a default form name of fileHttpRequestBuilder.UploadFile("https://localhost:7044/HttpRemote/AddFile", @"C:\Workspaces\httptest.jpg", "file")    // Set the content type (file type)    .SetContentType("image/jpeg")    // Set the allowed file extensions    .SetAllowedFileExtensions([".jpg", ".png"])    .SetAllowedFileExtensions(".jpg;.png")    // Set the allowed file size, in bytes    .SetMaxFileSizeInBytes(5 * 1024 * 1024)    // Set the interval for file transfer progress (notifications)    .SetProgressInterval(TimeSpan.FromSeconds(1))    // Set the action to perform when the file transfer starts    .SetOnTransferStarted(() => {})    // Set the delegate to execute when the transfer progress changes    .SetOnProgressChanged(async progress => { })    // Set the action to perform when the file transfer completes; the delegate parameter is the total time spent on the transfer (in milliseconds)    .SetOnTransferCompleted(duration => {})    // Set the action to perform when the file transfer encounters an exception    .SetOnTransferFailed(exception => {})    // Set the HTTP file transfer event handler; CustomFileTransferEventHandler is a type implementing the IHttpFileTransferEventHandler interface    .SetEventHandler<CustomFileTransferEventHandler>()    .SetEventHandler(typeof(CustomFileTransferEventHandler))    // Append multipart form content    .WithMultipart(multipart => {});    // Set the HttpRequestBuilder instance    .With(builder => {});   // Supports further extensions

After successfully building the HttpFileUploadBuilder instance via the HttpRequestBuilder.UploadFile method, you can use the Send method or the asynchronous SendAsync method to perform the send operation.

cs
httpRemoteService.Send(httpFileUploadBuilder, cancellationToken);await httpRemoteService.SendAsync(httpFileUploadBuilder, cancellationToken);