ZNetCS.AspNetCore.ResumingFileResults 6.0.1

dotnet add package ZNetCS.AspNetCore.ResumingFileResults --version 6.0.1
NuGet\Install-Package ZNetCS.AspNetCore.ResumingFileResults -Version 6.0.1
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="ZNetCS.AspNetCore.ResumingFileResults" Version="6.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ZNetCS.AspNetCore.ResumingFileResults --version 6.0.1
#r "nuget: ZNetCS.AspNetCore.ResumingFileResults, 6.0.1"
#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.
// Install ZNetCS.AspNetCore.ResumingFileResults as a Cake Addin
#addin nuget:?package=ZNetCS.AspNetCore.ResumingFileResults&version=6.0.1

// Install ZNetCS.AspNetCore.ResumingFileResults as a Cake Tool
#tool nuget:?package=ZNetCS.AspNetCore.ResumingFileResults&version=6.0.1

ZNetCS.AspNetCore.ResumingFileResults

NuGet Build

A small package to allow using resume during transfering data over MVC application in ASP.NET Core.

It allows provide ETag header as well as Last-Modified one. It also supports following precondition headers: If-Match, If-None-Match, If-Modified-Since , If-Unmodified-Since, If-Range.

ASP.NET Core 2.0

As from version 2.0 resuming is supported out of box inside ASP.NET Core. So all code related to resuming was removed. I left only part for Content-Disposition inline. Now all code relies on base .NET classes. Also support for multipart request is removed. To support that I would have to copy a lot of original code, because currently there is no way to simple override some part of base classes.

Installing

Install using the ZNetCS.AspNetCore.ResumingFileResults NuGet package

PM> Install-Package ZNetCS.AspNetCore.ResumingFileResults

Usage

When you install the package, it should be added to your .csproj. Alternatively, you can add it directly by adding:

<ItemGroup>
    <PackageReference Include="ZNetCS.AspNetCore.ResumingFileResults" Version="6.0.1" />
</ItemGroup>

.NET 6

// Add services to the container.
builder.Services.AddResumingFileResult();

.NET 5 and Below

In order to use the ResumingFileResults, you must configure the services in the ConfigureServices call of Startup:

public void ConfigureServices(IServiceCollection services)
{
    services.AddResumingFileResult();
}

Use inside controller

Then in your controller you can use it in similar way as build in FileResult helpers.

using ZNetCS.AspNetCore.ResumingFileResults.Extensions;
...
public IActionResult FileContents()
{
    string webRoot = this.hostingEnvironment.WebRootPath;
    var contents = System.IO.File.ReadAllBytes(Path.Combine(webRoot, "TestFile.txt"));

    return this.ResumingFile(contents, "text/plain", "TestFile.txt");
}

...

public IActionResult FileStream()
{
    string webRoot = this.hostingEnvironment.WebRootPath;
    FileStream stream = System.IO.File.OpenRead(Path.Combine(webRoot, "TestFile.txt"));
    return this.ResumingFile(stream, "text/plain", "TestFile.txt");
}

...
       
public IActionResult PhysicalFile()
{
    string webRoot = this.hostingEnvironment.WebRootPath;
    return this.ResumingPhysicalFile(Path.Combine(webRoot, "TestFile.txt"), "text/plain", "TestFile.txt");
}

...
    
public IActionResult VirtualFile()
{
    return this.ResumingFile("TestFile.txt", "text/plain", "TestFile.txt");
}

Above examples will serve your data as Content-Disposition: attachment. When fileName is not provided then data is served as Content-Disposition: inline. Additionaly it is possible provide ETag and LastModified headers.

public IActionResult File()
{
    return new ResumingVirtualFileResult("TestFile.txt", "text/plain", "\"MyEtagHeader\"") 
    { 
        FileDownloadName = "TestFile.txt", 
        LastModified = DateTimeOffset.Now 
    };
}
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 3.1

    • No dependencies.
  • net5.0

    • No dependencies.
  • net6.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
6.0.1 4,788 2/3/2022
2.2.0 4,563 10/11/2019
2.1.2 2,942 8/8/2018
2.1.1 1,077 6/20/2018
2.1.0-preview2-30045 790 2/7/2018
2.0.0 1,130 8/30/2017
1.0.7 1,229 5/19/2017
1.0.6 1,197 11/23/2016
1.0.5 1,328 9/28/2016
1.0.3 1,188 9/13/2016
1.0.2 1,184 9/12/2016
1.0.1 1,490 9/11/2016

Breaking Change: Drop support for netstandard and .net framework. Code refactoring. Dependency update. Library is now strong name signed.