FileDownloadBlazor 0.0.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package FileDownloadBlazor --version 0.0.3                
NuGet\Install-Package FileDownloadBlazor -Version 0.0.3                
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="FileDownloadBlazor" Version="0.0.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FileDownloadBlazor --version 0.0.3                
#r "nuget: FileDownloadBlazor, 0.0.3"                
#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 FileDownloadBlazor as a Cake Addin
#addin nuget:?package=FileDownloadBlazor&version=0.0.3

// Install FileDownloadBlazor as a Cake Tool
#tool nuget:?package=FileDownloadBlazor&version=0.0.3                

FileDownloadBlazor

Download file in blazor apps. Supports asynchronously and synchronously downloading from uris, byte arrays, and streams.

Notes

  1. ISyncFileDownloader is not registered as a service, use IFileDownloader.Sync instead.
  2. IFileDownloader.Sync is only available for Blazor WebAssembly.
  3. IFileDownloader.Sync may throw exceptions if the JavaScript module has not been imported, since the modules can only be imported asynchronously.
    • But you don't have to worry about that, since it's not multithreaded.
    • If you do want to ensure it has been imported, use IFileDownloader.CheckJavaScriptModuleAsync.

Usage

In Program.cs:

using FileDownloadBlazor.Extensions;

builder.Services.AddFileDownloadBlazor();

In your page:

@using FileDownloadBlazor
@inject IFileDownloader Downloader

<button @onclick="TestAsyncUri">TestAsyncUri</button>
<button @onclick="TestAsyncBytes">TestAsyncBytes</button>
<button @onclick="TestAsyncStream">TestAsyncStream</button>
<button @onclick="TestSyncUri">TestSyncUri</button>
<button @onclick="TestSyncBytes">TestSyncBytes</button>
<button @onclick="TestSyncStream">TestSyncStream</button>

@code
{
    private async Task TestAsyncUri()
    {
        await Downloader.DownloadAsync(
            "./", 
            "uri-async.html");
    }

    private async Task TestAsyncBytes()
    {
        await Downloader.DownloadAsync(
            [72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, 33],
            "bytes-async.txt");
    }

    private async Task TestAsyncStream()
    {
        using var stream = new MemoryStream();
        stream.WriteByte(72);
        stream.WriteByte(101);
        stream.Position = 1;
        await Downloader.DownloadAsync(
            stream,
            "stream-async.txt");
    }

    private void TestSyncUri()
    {
        Downloader.Sync.Download(
            "./",
            "uri-sync.html");
    }

    private void TestSyncBytes()
    {
        Downloader.Sync.Download(
            [72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, 33],
            "bytes-sync.txt");
    }

    private void TestSyncStream()
    {
        using var stream = new MemoryStream();
        stream.WriteByte(72);
        stream.WriteByte(101);
        stream.Position = 1;
        Downloader.Sync.Download(
            stream,
            "stream-sync.txt");
    }
}
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
0.0.4 35 11/1/2024
0.0.3 60 10/25/2024
0.0.2 46 10/25/2024
0.0.1 46 10/25/2024