S3

Dosaic.Plugins.Persistence.S3 is a plugin that allows other Dosaic components to interact with S3-compatible storage.

Installation

To install the nuget package follow these steps:

dotnet add package Dosaic.Plugins.Persistence.S3

or add as package reference to your .csproj


<PackageReference Include="Dosaic.Plugins.Persistence.S3" Version=""/>

Appsettings.yml

Configure your appsettings.yml with these properties:

s3:
  endpoint: ""
  bucketPrefix: "" # optional, used to prefix all bucket names
  accessKey: ""
  secretKey: ""
  region: ""
  useSsl: true
  healthCheckPath: ""

Registration and Configuration

File Storage with pre-defined buckets

To use the file storage functionality with a pre-defined bucket list, define an enum for your buckets:

Then register the file storage for your bucket enum:

This registers IFileStorage<MyBucket> which can be injected into your services.

Automatic Bucket Migration Service

To ensure buckets are created automatically when your application starts, register the migration service: The service will automatically create all buckets defined in your enum.

File Storage without enum based buckets

The plugin automatically registers IFilestorage with the service collection.

When using IFilestorage instead of IFilestorage<MyBucket>, there is no bucket migration service since, we don't know what buckets should exist at runtime.

Therefor you must create your bucket at runtime

Basic setup without a dosaic web host (optional)

If you don't use the dosaic webhost, which automatically configures the DI container, you'll need to register the S3 plugin manually:

Custom mimetype definitions

Filetype Definitions

You can define/override custom definitions for each Filetype by implementing the IFileTypeDefinitionResolver interface.

And then passing it to the following method so it gets replaced in the serviceColletion:

The default implementation is DefaultFileTypeDefinitionResolver can uses all the default definitions from classMimeDetective.Definitions.DefaultDefinitions.

ContentInspector Definitions

You can define/override definitions the content inspector by replacing the IContentInspector in the IoC with your own implementation.

Example

The plugin uses by default Definitions = DefaultDefinitions.All().

Working with Files

Blob file creation

Mimetype detection

If the MetaData[BlobFileMetaData.ContentType] of the BlobFile is not set, the plugin will automatically try to detect the mimetype in the following order:

  1. If the MetaData[BlobFileMetaData.FileExtension] is set, it will use the IFileTypeDefinitionResolver to get the mimetype.

  2. If the MetaData[BlobFileMetaData.FileExtension] is not set, it will use the IContentInspector to detect the mimetype based on the file content.

  3. If the mimetype cannot be detected, it will default to application/octet-stream.

Validation

Validation depends on the FileType of the SetAsync() method and the detected mimetype result inMetaData[BlobFileMetaData.ContentType].

If FileType.Any is used, no validation is performed.

Otherwise, the detected mimetype must match one of the allowed mimetypes defined in the FileType enum (can be customized via IFileTypeDefinitionResolver).

Usage with permission checks or acl's

Example of using the file storage interface:

Example usage in a controller

Last updated