Skip to content

Commit 1071037

Browse files
committed
doc(Uploader): add UseUploaderStaticFiles extension method
1 parent b6660ea commit 1071037

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the Apache 2.0 License
3+
// See the LICENSE file in the project root for more information.
4+
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone
5+
6+
using Microsoft.Extensions.FileProviders;
7+
8+
namespace Microsoft.AspNetCore.Builder;
9+
10+
static class WebApplicationExtensions
11+
{
12+
public static void UseUploaderStaticFiles(this WebApplication app)
13+
{
14+
var uploader = Path.Combine(app.Environment.WebRootPath, "images", "uploader");
15+
Directory.CreateDirectory(uploader);
16+
17+
app.UseStaticFiles(new StaticFileOptions
18+
{
19+
FileProvider = new PhysicalFileProvider(uploader),
20+
RequestPath = "/images/uploader"
21+
});
22+
}
23+
}

src/BootstrapBlazor.Server/Program.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
app.UseExceptionHandler("/Error", createScopeForErrors: true);
3636
}
3737

38+
// 增加上传目录静态资源文件
39+
app.UseUploaderStaticFiles();
40+
3841
app.UseAntiforgery();
3942
app.UseBootstrapBlazor();
4043

0 commit comments

Comments
 (0)