Skip to content

Commit 179b0db

Browse files
committed
Update Configure.AppHost.cs
1 parent 1759516 commit 179b0db

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

MyApp/Configure.AppHost.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using Microsoft.AspNetCore.Mvc.Rendering;
2+
using ServiceStack.Configuration;
23
using ServiceStack.IO;
4+
using ServiceStack.Text;
35

46
[assembly: HostingStartup(typeof(MyApp.AppHost))]
57

@@ -12,6 +14,22 @@ public void Configure(IWebHostBuilder builder) => builder
1214
// Configure ASP.NET Core IOC Dependencies
1315
context.Configuration.GetSection(nameof(AppConfig)).Bind(AppConfig.Instance);
1416
services.AddSingleton(AppConfig.Instance);
17+
18+
// Enable Managed File Uploads: https://docs.servicestack.net/locode/files-overview
19+
var fileFs = new FileSystemVirtualFiles(context.HostingEnvironment.ContentRootPath);
20+
services.AddPlugin(new FilesUploadFeature(
21+
// User Writable, public readable
22+
new UploadLocation("pub",
23+
fileFs,
24+
readAccessRole: RoleNames.AllowAnon,
25+
maxFileBytes: 10 * 1024 * 1024,
26+
resolvePath:ctx => $"pub/{DateTime.UtcNow.ToUnixTime()}/{ctx.FileName}"),
27+
// User Writable, User Readable
28+
new UploadLocation("secure",
29+
fileFs,
30+
maxFileBytes: 10 * 1024 * 1024,
31+
resolvePath:ctx => $"/users/{ctx.UserAuthId}/{ctx.FileName}")
32+
));
1533
});
1634

1735
public override void Configure()

0 commit comments

Comments
 (0)