6.26File Transfer Event Handler

Created on Aug 17, 2026~4 min read

The IHttpFileTransferEventHandler interface allows you to define preprocessing operations for downloading or uploading files. By implementing this interface, you can create a custom file transfer event handler, such as the CustomFileTransferEventHandler class:

cs
public class CustomFileTransferEventHandler : IHttpFileTransferEventHandler{    // Action to perform when the file transfer starts    public void OnTransferStarted() {}    // Action to perform when the transfer progress changes    public Task OnProgressChangedAsync(FileTransferProgress fileTransferProgress) {}    // Action to perform when the file transfer completes    public void OnTransferCompleted(long duration) {}    // Action to perform when the file transfer encounters an exception    public void OnTransferFailed(Exception exception) {}}

To enable this handler in your application, register the CustomFileTransferEventHandler service in the Startup.cs or Program.cs file:

cs
services.TryAddSingleton<CustomFileTransferEventHandler>();

Next, you can specify this handler when building the HTTP request:

cs
HttpRequestBuilder.UploadFile("https://localhost:7044/HttpRemote/AddFile", @"C:\Workspaces\httptest.jpg", "file")    .SetEventHandler<CustomFileTransferEventHandler>();HttpRequestBuilder.UploadFile("https://localhost:7044/HttpRemote/AddFile", @"C:\Workspaces\httptest.jpg", "file")    .SetEventHandler(typeof(CustomFileTransferEventHandler));    // Set it using the type approach