https://github.com/lurumad/aspnetfileproviders
ASP.NET Core FileProviders
https://github.com/lurumad/aspnetfileproviders
aspnetcore aspnetcoremvc csharp fileproviders
Last synced: 25 days ago
JSON representation
ASP.NET Core FileProviders
- Host: GitHub
- URL: https://github.com/lurumad/aspnetfileproviders
- Owner: lurumad
- Created: 2018-08-27T12:37:31.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-08-29T16:05:19.000Z (almost 8 years ago)
- Last Synced: 2025-02-22T02:41:24.852Z (over 1 year ago)
- Topics: aspnetcore, aspnetcoremvc, csharp, fileproviders
- Language: C#
- Size: 32.2 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://ci.appveyor.com/project/lurumad/aspnetfileproviders) [](https://www.nuget.org/packages/Lurumad.AspNet.FileProviders.AzureStorage/)
[](https://ci.appveyor.com/project/lurumad/aspnetfileproviders/history)
# Lurumad.AspNet.FileProviders
A collection of File Providers for ASP.NET Core:
- **Azure Blob Storage File Provider** for ASP.NET Core.
This file provider allows our ASP.NET Core application to use Azure blobs as if they would actually be files stored in server disk.
As an example, we could use this provider to make our ASP.NET application serve blobs as static files, based in a relative request path.
If we would have following blobs inside an Azure Blob Container:
- Blob1.txt
- Blob2.txt
and we'd configure the provider with "/site" relative path, we could ask for the blobs using following url's:
https://server/site/Blob1.txt and https://server/site/Blob2.txt
## Getting Started with Azure Storage File Provider
1. Install the Nuget Package into your ASP.NET Core application.
``` PowerShell
Install-Package Lurumad.AspNet.FileProviders.AzureStorage
```
2. Usage
An example of using AzureBlobStorageFileProvider with static files and directory browser:
```csharp
public class Startup
{
private const string RequestPath = "/site";
private readonly IConfiguration configuration;
public Startup(IConfiguration configuration)
{
this.configuration = configuration;
}
public void ConfigureServices(IServiceCollection services)
{
services.Configure(configuration.GetSection(nameof(AzureOptions)));
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
var fileProvider = new AzureBlobStorageFileProvider(configuration.GetSection());
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = fileProvider,
RequestPath = RequestPath
})
.UseDirectoryBrowser(new DirectoryBrowserOptions
{
FileProvider = fileProvider,
RequestPath = RequestPath
});
}
}
```
More advanced scenario of using AzureBlobStorageFileProvider with Razor View Engine as a email template system:
```csharp
public class Startup
{
private readonly IConfiguration configuration;
public Startup(IConfiguration configuration)
{
this.configuration = configuration ?? throw new System.ArgumentNullException(nameof(configuration));
}
public void ConfigureServices(IServiceCollection services)
{
services
.Configure(configuration.GetSection(nameof(AzureOptions)))
.AddSingleton(configuration.GetSection())
.AddMvcCore()
.AddViews()
.AddRazorViewEngine(engine =>
{
engine.ViewLocationFormats.Clear();
engine.ViewLocationFormats.Add($"{{0}}/{{1}}/{{1}}{RazorViewEngine.ViewExtension}");
engine.ViewLocationFormats.Add($"Shared/{{0}}{RazorViewEngine.ViewExtension}");
engine.FileProviders.Add(new AzureBlobStorageFileProvider(configuration.GetSection()));
})
.AddJsonFormatters()
.AddApiExplorer()
.AddFluentValidation(fv => fv.RegisterValidatorsFromAssemblyContaining())
.Services
.AddOpenApi()
.AddScoped()
.AddScoped()
.AddScoped();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app
.UseAuthentication()
.UseOpenApi()
.UseMvc();
}
}
```
You can play with the samples.