FileDownloadBlazor 0.0.4
dotnet add package FileDownloadBlazor --version 0.0.4
NuGet\Install-Package FileDownloadBlazor -Version 0.0.4
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.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FileDownloadBlazor --version 0.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: FileDownloadBlazor, 0.0.4"
#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.4 // Install FileDownloadBlazor as a Cake Tool #tool nuget:?package=FileDownloadBlazor&version=0.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
FileDownloadBlazor
Download file in blazor apps. Supports asynchronously and synchronously downloading from uris, byte arrays, and streams.
Notes
ISyncFileDownloader
is not registered as a service, useIFileDownloader.Sync
instead.IFileDownloader.Sync
is only available for Blazor WebAssembly.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 | Versions 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.
-
net8.0
- Microsoft.AspNetCore.Components.Web (>= 8.0.10)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.