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
jsRuntimeIJSRuntimeThe 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
fileNamestringThe name of the file to download.
bytesbyte[]The file content as a byte array.
contentTypestringThe MIME content type of the file.
cancellationTokenCancellationTokenA cancellation token to observe.
Returns
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
fileNamestringThe name of the file to download.
streamStreamThe stream containing the file content.
contentTypestringThe MIME content type of the file.
cancellationTokenCancellationTokenA cancellation token to observe.
Returns
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
fileNamestringThe name of the file to download.
textstringThe text content of the file.
encodingEncodingThe encoding to use when converting the text to bytes.
contentTypestringThe MIME content type of the file.
cancellationTokenCancellationTokenA cancellation token to observe.