Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/filipw/Strathweb.AspNetCore.AzureBlobFileProvider
https://github.com/filipw/Strathweb.AspNetCore.AzureBlobFileProvider
Last synced: 5 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/filipw/Strathweb.AspNetCore.AzureBlobFileProvider
- Owner: filipw
- License: mit
- Created: 2018-06-25T11:07:51.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-06-02T11:06:29.000Z (over 2 years ago)
- Last Synced: 2024-11-07T15:03:53.333Z (7 days ago)
- Language: C#
- Size: 29.3 KB
- Stars: 55
- Watchers: 9
- Forks: 22
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Strathweb.AspNetCore.AzureBlobFileProvider
Azure Blob Storage file provider (`IFileProvider`) for ASP.NET Core.
### Installation
```
Install-Package Strathweb.AspNetCore.AzureBlobFileProvider
```### Usage
Configure access to your Blob Storage via storage account connection string or SAS token.
Below is the usage example for both flows - where access to files from Blob Storage is enabled on the `/files` route (including directory browsing in the browser).
**Connection string**
```csharp
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
var blobOptions = new AzureBlobOptions
{
ConnectionString = "{my connection string}",
DocumentContainer = "{blob container name}"
}
var azureBlobFileProvider = new AzureBlobFileProvider(blobOptions);
services.AddSingleton(azureBlobFileProvider);
}public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
var blobFileProvider = app.ApplicationServices.GetRequiredService();
app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = blobFileProvider,
RequestPath = "/files"
});app.UseDirectoryBrowser(new DirectoryBrowserOptions
{
FileProvider = blobFileProvider,
RequestPath = "/files"
});
}
}
```**Token** (need to provide the URL of the storage separately)
```csharp
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
var blobOptions = new AzureBlobOptions
{
BaseUri = "{base URL of the storage account}",
Token = "{SAS token}",
DocumentContainer = "{blob container name}"
}
var azureBlobFileProvider = new AzureBlobFileProvider(blobOptions);
services.AddSingleton(azureBlobFileProvider);
}public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
var blobFileProvider = app.ApplicationServices.GetRequiredService();
app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = blobFileProvider,
RequestPath = "/files"
});app.UseDirectoryBrowser(new DirectoryBrowserOptions
{
FileProvider = blobFileProvider,
RequestPath = "/files"
});
}
}
```In case both `ConnectionString` and `Token` are present, connection string is given the preference.
### Current limitations
The watch functionality of the file provider is currently not supported.