Skip to content

Mk.FileStorage is a simple solution to integrate a File Storage in your ASP.NET Core project.

License

Notifications You must be signed in to change notification settings

mknet3/Mk.FileStorage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mk.FileStorage

Mk.FileStorage is a simple solution to integrate a File Storage in your ASP.NET Core project using streaming.

CI Continuous Deployment PREVIEW

Getting Started

Prerequisites

  • .NET Core 3.1 / 5.0
  • Docker (optional, to mock Azure Blob Storage with Azurite)

Development Environment

We can use Azurite to emulate an Azure Storage. We can run this dependency with docker-compose:

docker-compose up

Sample

To be able to upload files from your project to Azure Storage only you need add this endpoint in the Startup:

    public void Configure(IApplicationBuilder app)
    {
        app.UseRouting();

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapMkFileStorage();
        });
    }

The default endpoint is /files, but you can choice other setting pattern:

    public void Configure(IApplicationBuilder app)
    {
        app.UseRouting();

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapMkFileStorage(pattern: "otherendpoint");
        });
    }

You can register services calling AddAzureMkFileStorage with configuration and connection string:

    public void ConfigureServices(IServiceCollection services)
    {
        var connectionString = _configuration.GetConnectionString("AzureBlobStorage");

        if (_env.IsDevelopment())
        {
            CreateContainerIfNotExists(connectionString);
        }

        services.AddAzureMkFileStorage(_configuration, connectionString);
    }

Configuration can be as follow in appsettings:

    {
      "AzureBlobStorage": {
        "ContainerName": "default"
      }
    }

Run sample in Visual Studio or with command line:

dotnet run --project src\Mk.FileStorage.Sample\Mk.FileStorage.Sample.csproj

And upload/download files from https://localhost:5001/files/{fileName}

About

Mk.FileStorage is a simple solution to integrate a File Storage in your ASP.NET Core project.

Resources

License

Stars

Watchers

Forks

Packages

No packages published