Image Providers
ImageSharp.Web determines the location of a source image to process via the registration and application of image providers.
Note
It is possible to configure your own image provider by implementing and registering your own version of the IImageProvider interface.
The following providers are available for the middleware. Multiples providers can be registered and will be queried for a URL match in the order of registration.
PhysicalFileSystemProvider
The PhysicalFileSystemProvider will allow the processing and serving of image files from the web root folder. This is the default provider installed when configuring the middleware.
Url matching for this provider follows the same rules as conventional static files.
AzureBlobStorageImageProvider
This provider allows the processing and serving of image files from Azure Blob Storage and is available as an external package installable via NuGet
PM > Install-Package SixLabors.ImageSharp.Web.Providers.Azure -Version VERSION_NUMBER
Once installed the provider AzureBlobContainerClientOptions can be configured as follows:
// Configure and register the containers.
// Alteratively use `appsettings.json` to represent the class and bind those settings.
.Configure<AzureBlobStorageImageProviderOptions>(options =>
{
// The "BlobContainers" collection allows registration of multiple containers.
options.BlobContainers.Add(new AzureBlobContainerClientOptions
{
ConnectionString = {AZURE_CONNECTION_STRING},
ContainerName = {AZURE_CONTAINER_NAME}
});
})
.AddProvider<AzureBlobStorageImageProvider>()
Url requests are matched in accordance to the following rule:
/{CONTAINER_NAME}/{BLOB_FILENAME}
AWSS3StorageImageProvider
This provider allows the processing and serving of image files from Amazon Simple Storage Service (Amazon S3) and is available as an external package installable via NuGet
PM > Install-Package SixLabors.ImageSharp.Web.Providers.AWS -Version VERSION_NUMBER
Once installed the cache AWSS3StorageImageProviderOptions can be configured as follows:
// Configure and register the buckets.
// Alteratively use `appsettings.json` to represent the class and bind those settings.
.Configure<AWSS3StorageImageProviderOptions>(options =>
{
// The "S3Buckets" collection allows registration of multiple buckets.
options.S3Buckets.Add(new AWSS3BucketClientOptions
{
Endpoint = AWS_ENDPOINT,
BucketName = AWS_BUCKET_NAME,
AccessKey = AWS_ACCESS_KEY,
AccessSecret = AWS_ACCESS_SECRET,
Region = AWS_REGION
});
})
.AddProvider<AWSS3StorageImageProvider>()
Url requests are matched in accordance to the following rule:
/{AWS_BUCKET_NAME}/{OBJECT_FILENAME}
Which is to say that the AWS S3 bucket name must appear in the Url so it can be matched with the correct S3 configuration. If you wished to override this and provide a deafult, this can be done using URL Rewriting middleware.