UFile.PartialUploader 1.2.0

dotnet add package UFile.PartialUploader --version 1.2.0
                    
NuGet\Install-Package UFile.PartialUploader -Version 1.2.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="UFile.PartialUploader" Version="1.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="UFile.PartialUploader" Version="1.2.0" />
                    
Directory.Packages.props
<PackageReference Include="UFile.PartialUploader" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add UFile.PartialUploader --version 1.2.0
                    
#r "nuget: UFile.PartialUploader, 1.2.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package UFile.PartialUploader@1.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=UFile.PartialUploader&version=1.2.0
                    
Install as a Cake Addin
#tool nuget:?package=UFile.PartialUploader&version=1.2.0
                    
Install as a Cake Tool

UFile.PartialUploader

Chunked upload server for .NET. Large files are received in small parts, each part is saved with retry, and once the final part arrives the parts are merged into the original file.

For browser clients use the companion package partial-uploader, which speaks exactly this protocol. A server-to-server client is included as well.

This is the server side. It has no ASP.NET Core UI of its own — you expose it through your own controller.

Install

dotnet add package UFile.PartialUploader

Requires net10.0 and the ASP.NET Core shared framework.

Register

public static IServiceCollection AddServices(this IServiceCollection services)
{
    services.AddUFile("App_Data", "tmp");

    // or with full control
    services.AddUFile(o =>
    {
        o.BasePath = "App_Data";
        o.TempFolderName = "tmp";
        o.ChunkSize = 5 * 1024 * 1024;      // client-side chunk size used by the server-to-server client
        o.UploadRetryCount = 3;              // attempts per chunk request
        o.UploadRetryDelayMilliseconds = 500;
        o.ChunkDelayMilliseconds = 0;        // pause between chunks (server-to-server)
        o.MaxChunkBytes = 32 * 1024 * 1024;  // reject oversized chunks; 0 = unlimited
    });

    return services;
}

Without DI, set the static fields directly — they are still honoured:

UFileHelper.BasePath = "App_Data";
UFileHelper.TempFolderName = "tmp";
UFileHelper.UploadChunkSize = 26214400;

Receive uploads

[ApiController]
[Route("api/[controller]")]
public class FileController(IUFileService uFileService) : ControllerBase
{
    [HttpPost("upload")]
    public async Task<IActionResult> Upload() =>
        StatusCode(await uFileService.UploadChunkFiles(Request));
}

Malformed requests now return 400 instead of throwing.

For richer results use UploadChunkDetailed, which returns the status code plus a failure kind and a message:

var result = await uFileService.UploadChunkDetailed(Request);
// result.StatusCode, result.Failure (InvalidRequest, PayloadTooLarge, ChunkMissing, ...), result.Message

Server-to-server upload

public class Test(IUFileService uFileService)
{
    public async Task Upload()
    {
        var path = Path.Combine(Directory.GetCurrentDirectory(), "App_Data", "path/to/file.txt");

        var res = await uFileService.UploadWithPartialFileAsync("https://example.com/upload", path,
            new Dictionary<string, string> { ["Authorization"] = "Bearer token" });

        if (!res.success)
            Console.Error.WriteLine($"{res.code}: {res.message} (HTTP {res.statusCode})");
    }
}

chunkSize defaults to 0, meaning "use the configured size". Pass a positive value to override it per call. Only 2xx responses are treated as success; 4xx (except 429) and 5xx are retried according to UploadRetryCount and then reported as failures.

You can pass your own HttpClient to control lifetime, pooling and handlers:

await uFileService.UploadWithPartialFileAsync(url, path, headers, 0, httpClient);

Read a finished upload

var info = UFileHelper.GetFileInfo(tempFolderId);   // null if missing or unsafe
var path = info?.FullName;

// merged files live in: <BasePath>/<TempFolderName>/<fileGuid>/<filename>
UFileHelper.RemoveTempFolder(tempFolderId);

Protocol

Every chunk is posted as multipart/form-data:

Field Meaning
file the chunk bytes
fileGuid upload id, identical for every chunk
filename original file name
index zero-based chunk index
totalChunks total number of chunks
totalSize total file size in bytes
isDone "true" on the final chunk only

The server derives the stored chunk name from index, not from the client-supplied filename, so two chunks can never overwrite each other. If index is absent it is recovered from the {filename}_chunk_{index} suffix for backwards compatibility.

Security notes

  • fileGuid and filename are reduced to a bare name — path separators, .. and absolute paths are stripped, so a hostile client cannot escape the configured directories.
  • The resolved path is verified to stay inside the chunk/temp root, comparing with a trailing separator so a sibling directory sharing the prefix (App_Data/tmp-evil vs App_Data/tmp) is rejected.
  • MaxChunkBytes additionally bounds the real body size, not just what the client claims.

Development

dotnet build
dotnet test

Tests use xUnit v3 on Microsoft.Testing.Platform. Because the .NET 10 SDK dropped the VSTest path for MTP-based projects, the repository ships a global.json that opts dotnet test into the new runner:

{ "test": { "runner": "Microsoft.Testing.Platform" } }

Without it dotnet test fails with "Testing with VSTest target is no longer supported".

License

MIT

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.0 1,156 10/1/2026
1.1.7 1,303 3/12/2026
1.1.6 143 3/12/2026
1.1.5 227 12/31/2025
1.1.4 552 3/4/2025
1.1.3 388 10/4/2024
1.1.2 194 10/4/2024
1.1.1 197 10/4/2024
1.1.0 210 10/4/2024
1.0.9 223 10/4/2024
1.0.8 226 10/4/2024
1.0.7 335 6/16/2024
1.0.6 231 6/12/2024
1.0.5 255 6/2/2024
1.0.4 247 6/2/2024
1.0.3 218 6/2/2024
1.0.2 229 6/2/2024
1.0.1 227 6/2/2024
1.0.0 232 5/28/2024