
Download file download
For direct download of physical files
Razor
code<Button OnClick="DownloadFile">Click me to download the file</Button>
C#
codeprivate async Task DownloadFileAsync()
{
using var stream = await GenerateFileAsync();
await DownloadService.DownloadFromStreamAsync("test file", stream);
static async Task<Stream> GenerateFileAsync()
{
var ms = new MemoryStream();
var writer = new StreamWriter(ms);
await writer.WriteLineAsync("Self-generated and written text, here can be replaced with pictures or other content");
await writer.FlushAsync();
ms.Position = 0;
return ms;
}
}
Download files directly by setting the physical path
Demo
By setting the physical path of the folder, the files in the directory are packaged and compressed and downloaded
Demo
This simulation generates a text file of 1 million lines
, about 58M, which can be tested by yourself
Demo
The button sets the value of IsAsync
to true
for asynchronous download operation
Simulate the situation where the verification code is generated directly from the front-end page or the uploaded image is not saved and displayed directly.
Demo
Since the test uses the files under wwwroot
, there is no code generation, and wasm
cannot access the wwwroot
folder, so only the ssr
mode is available for the test. wasm
please test it yourself.

B station related video link
交流群