Table of Contents

Class DownloadFileService

Namespace
NuvTools.AspNetCore.Blazor.JSInterop
Assembly
NuvTools.AspNetCore.Blazor.dll

Provides JavaScript interop functionality for downloading files in Blazor applications.

public sealed class DownloadFileService : IDownloadFileService, IAsyncDisposable
Inheritance
DownloadFileService
Implements
Inherited Members

Remarks

Initializes a new instance of the DownloadFileService class.

Constructors

DownloadFileService(IJSRuntime)

Provides JavaScript interop functionality for downloading files in Blazor applications.

public DownloadFileService(IJSRuntime jsRuntime)

Parameters

jsRuntime IJSRuntime

The JavaScript runtime for interop operations.

Remarks

Initializes a new instance of the DownloadFileService class.

Methods

DisposeAsync()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.

public ValueTask DisposeAsync()

Returns

ValueTask

A task that represents the asynchronous dispose operation.

DownloadFileAsync(string, byte[], string, CancellationToken)

Downloads a file from a byte array.

public ValueTask DownloadFileAsync(string fileName, byte[] bytes, string contentType = "application/octet-stream", CancellationToken cancellationToken = default)

Parameters

fileName string

The name of the file to download.

bytes byte[]

The file content as a byte array.

contentType string

The MIME content type of the file.

cancellationToken CancellationToken

A cancellation token to observe.

Returns

ValueTask

A ValueTask representing the asynchronous operation.

DownloadFileAsync(string, Stream, string, CancellationToken)

Downloads a file from a stream. Large streams are sent in chunks to stay within SignalR message size limits.

public ValueTask DownloadFileAsync(string fileName, Stream stream, string contentType = "application/octet-stream", CancellationToken cancellationToken = default)

Parameters

fileName string

The name of the file to download.

stream Stream

The stream containing the file content.

contentType string

The MIME content type of the file.

cancellationToken CancellationToken

A cancellation token to observe.

Returns

ValueTask

A ValueTask representing the asynchronous operation.

DownloadFileFromTextAsync(string, string, Encoding, string, CancellationToken)

Downloads a file from a text string using the specified encoding.

public ValueTask DownloadFileFromTextAsync(string fileName, string text, Encoding encoding, string contentType = "text/plain", CancellationToken cancellationToken = default)

Parameters

fileName string

The name of the file to download.

text string

The text content of the file.

encoding Encoding

The encoding to use when converting the text to bytes.

contentType string

The MIME content type of the file.

cancellationToken CancellationToken

A cancellation token to observe.

Returns

ValueTask

A ValueTask representing the asynchronous operation.