SkillAgentSearch skills...

Strathweb.AspNetCore.AzureBlobFileProvider

No description available

Install / Use

/learn @filipw/Strathweb.AspNetCore.AzureBlobFileProvider
About this skill

Quality Score

0/100

Supported Platforms

Universal

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

    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<AzureBlobFileProvider>();
            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)

    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<AzureBlobFileProvider>();
            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.

Related Skills

View on GitHub
GitHub Stars56
CategoryDevelopment
Updated2d ago
Forks23

Languages

C#

Security Score

90/100

Audited on Apr 1, 2026

No findings