4.13Adding local path file content (progress)

Created on Aug 17, 2026~3 min read

Add file content from a local path to the multipart form content.

cs
HttpRequestBuilder.Post("https://furion.net")    .SetMultipartContent(multipart =>    {        // File stream approach        multipart.AddFileAsStream(@"C:\Workspaces\httptest.jpg", "file");        multipart.AddFileAsStream(@"C:\Workspaces\httptest.jpg", "file", "test.jpg");    // Custom file name        multipart.AddFileAsStream(@"C:\Workspaces\httptest.jpg", "file", "test.jpg", "image/jpeg");    // Custom media type; if Content-Type is not provided, it will be automatically resolved based on the file extension        // Byte array approach        multipart.AddFileAsByteArray(@"C:\Workspaces\httptest.jpg", "file");        multipart.AddFileAsByteArray(@"C:\Workspaces\httptest.jpg", "file", "test.jpg");    // Custom file name        multipart.AddFileAsByteArray(@"C:\Workspaces\httptest.jpg", "file", "test.jpg", "image/jpeg");    // Custom media type; if Content-Type is not provided, it will be automatically resolved based on the file extension    });

Additionally, the system provides the AddFileWithProgressAsStream method, which, compared to AddFileAsStream, allows you to obtain file transfer progress in real time. For example:

cs
// Create a channel for file transfer progress informationvar progressChannel = Channel.CreateUnbounded<FileTransferProgress>();HttpRequestBuilder.Post("https://furion.net")    .SetMultipartContent(multipart =>    {        multipart.AddFileWithProgressAsStream(@"C:\Workspaces\httptest.jpg", progressChannel, "file");    });// Subscribe to file transfer progress notificationsawait foreach (var fileTransferProgress in progressChannel.Reader.ReadAllAsync(cancellationToken)){    Console.WriteLine(fileTransferProgress.ToSummaryString());    // Delay one second each iteration    await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken);}

In this way, transfer progress information is printed every second during the file transfer. react-error-boundary