This repository contains BlobService for hosting on-permise. This is designed as plugable component and can be extended to store blobs in any storage.
The project is now in active development.
Full Documentation is available here.
http://blobservice.readthedocs.io
-
Create new ASP.NET Core project in you solution
-
Update WebConfig to enable DELETE and PUT method support
<system.webServer>
<modules>
<remove name="WebDAVModule" />
</modules>
<handlers>
<remove name="WebDAV" />
</handlers>
- Install folowing Nuget packages
Install-Package BlobService.Core
Install-Package BlobService.MetaStore.EntityFrameworkCore
Install-Package BlobService.Storage.FileSystem
- Add folowing code to your Startup.cs
//Usings
using BlobService.Core.Configuration;
using BlobService.MetaStore.EntityFrameworkCore;
using BlobService.MetaStore.EntityFrameworkCore.Configuration;
using BlobService.Storage.FileSystem;
using BlobService.Storage.FileSystem.Configuration;
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
// Cors Policy
services.AddCors(opts =>
{
opts.AddPolicy("AllowAllOrigins",
builder =>
{
builder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowCredentials();
});
});
// Add DB Context
services.AddDbContext<BlobServiceContext>(opts =>
{
// Example
opts.UseSqlServer("Server=(localdb)\\mssqllocaldb;Database=BS;Trusted_Connection=True;MultipleActiveResultSets=true");
});
// Adds Blob services core services
services.AddBlobService(opts =>
{
opts.CorsPolicyName = "AllowAllOrigins";
opts.MaxBlobSizeInMB = 100;
})
// Registers FileSystem Storage Service for persisting files in filesystem in specified path
.AddFileSystemStorageService<FileSystemStorageService>(opts =>
{
// Make sure to give Write permission to IIS User
opts.RootPath = @"C:\blobs";
})
.AddEfMetaStores<BlobServiceContext>();
}
public void Configure(IApplicationBuilder app)
{
// Use BlobService Middlwares (mvc)
app.UseBlobService();
}
}
- Execute folowing command in Console
Add-Migrations
and specify name for your migration
- And finally execute
Update-Database
- Get all containers
Method: GET
Endpoint: www.example.com/containers
- Add container
Method: POST
Endpoint: www.example.com/containers
Data: {"name" : "ContainerName"}
- Get container by name
Method: GET
Endpoint: www.example.com/containers/{name}
- Get all blobs from container
Method: GET
Endpoint: www.example.com/containers/{id}/blobs
- Update container's name
Method: PUT
Endpoint: www.example.com/containers/{id}
Data: {"name" : "NewContainerName"}
- Delete container
Method: DELETE
Endpoint: www.example.com/containers/{id}