Blazor-Blazor.FileUtilities

[删除(380066935@qq.com或微信通知)]

Blazor.FileUtilities

NoelTheis/Blazor.FileUtilities: Provides simple methods for downloading or opening files in a Blazor application (github.com)

Provides easy methods for downloading or opening files in a Blazor application.

This is just a small wrapper around a bit of javascript that can turn a stream into a blob and either open it in a new window or trigger a download.

Uploading was not part of the goal as the existing Solution does not really need much simplification.

The project relies on MimeTypesMap to figure out the correct mime type for opening files.

Targets

.Net 6

Install

PM> Install-Package Blazor.FileUtilities

Usage

Add services.

Services.AddBlazorFileUtilities();

Inject the service into any component.

@using Blazor.FileUtilities

@inject FileService FileService

Open file from stream. The file name (with extension) is required to figure out the correct mime type.

await FileService.Open(stream, FileName);

Alternatively the mime type can be supplied directly.

await FileService.Open(stream, FileName, useMimeType: true);

Download file from stream.

await FileService.Download(stream, FileName);

Demo

WASM