Setting Up

Blob Management has not been released yet; see the overview.

This page sets up the host that runs Blob Management: the application itself when the module is in its process, or Blob Management's own service. Which of the two is a choice described in Hosting Modes.

Installation

Reference Dignite.Abp.BlobManagement.Application, Dignite.Abp.BlobManagement.HttpApi and the database provider, Dignite.Abp.BlobManagement.EntityFrameworkCore or Dignite.Abp.BlobManagement.MongoDB, and depend on their modules:

[DependsOn(
    typeof(BlobManagementApplicationModule),
    typeof(BlobManagementHttpApiModule),
    typeof(BlobManagementEntityFrameworkCoreModule) // or BlobManagementMongoDbModule
)]
public class MyHostModule : AbpModule
{
}

Dignite.Abp.BlobManagement.HttpApi is needed for remote applications, public read, the directory and usage APIs and the management page; a host whose only caller is an application in the same process can leave it out.

The database objects have the Blob prefix (BlobFileDescriptors, BlobDirectoryDescriptors) and use the BlobManagement connection string, falling back to Default. With EF Core, call ConfigureBlobManagement() in your migrations DbContext and add a migration:

protected override void OnModelCreating(ModelBuilder builder)
{
    base.OnModelCreating(builder);

    builder.ConfigureBlobManagement();
}

With MongoDB, BlobManagementMongoDbModule keeps the files and directories in the BlobFileDescriptors and BlobDirectoryDescriptors collections.

Blob Management processes pictures with SkiaSharp, which comes with it: the images preset stores a JPEG, and most PNGs, as WebP and resizes through ABP's image manipulation SkiaSharp provider, and public reads resize on request with it. The domain module depends on the SkiaSharp image contributors module, which also makes ABP's SkiaSharp resizer turn photos upright and changes its default sampling and quality for the whole host. SkiaSharp brings its native libraries for Windows and macOS only: on Linux, reference SkiaSharp.NativeAssets.Linux in this host, or every picture fails to process.

Managed Containers

A managed container is an ABP BLOB container of this host, declared one with UseBlobManagementContainer. Its storage provider (UseFileSystem, UseAzure, ...) and its pipeline contributors are configured on the same container, as usual:

Configure<AbpBlobStoringOptions>(options =>
{
    // The storage beneath every managed container that names none of its own.
    options.Containers.ConfigureDefault(container =>
    {
        container.UseFileSystem(fs => fs.BasePath = "/var/lib/blobs");
    });

    options.Containers.Configure("media", container =>
    {
        container.UseBlobManagementContainer();
        container.UseImagesPreset(preset => preset.MaxWidth = 2048);
    });

    options.Containers.Configure("documents", container =>
    {
        container.UseBlobManagementContainer(managed => managed.AllowDirectories = true);
        container.UseDocumentsPreset();
    });
});

There is one kind of managed container: applications store in it by name through the provider and by id through the file service, and the management page shows both. BlobManagementContainerConfiguration has:

  • AllowDirectories: whether the container has a directory tree for its files addressed by id (Directories). Default: false - the container's files are one flat list, and every directory operation is refused (BlobManagement:DirectoriesNotAllowed).

Which applications may use a container over HTTP is not configured here: an OAuth client is granted the container's files in ABP's permission management (Granting an Application). An application in the same process is trusted and needs no grant.

Nor is whether a file is read publicly: that is the business system's call, made on each file - by the application's own container for the BLOBs it saves by name (Public Addresses), and when it stores a file by id or later (Public Files).

UseBlobManagementContainer also makes the container multi-tenant: every managed container keeps each tenant's files apart. Declare named containers only; a default container declared managed would make every container name one, and the host refuses to start.

Presets

A preset adds the BLOB Storing contributors a kind of file needs, in the order they have to run. Its parameters are numbers only.

Preset What it adds Defaults
UseImagesPreset Size limit, allowed types (JPEG, PNG, GIF, WebP), a JPEG stored as WebP (StoreJpegAsWebp, at WebpQuality), a PNG stored as lossless WebP (StorePngAsWebp, from PngWebpMinSizeInBytes), metadata removal and a resize into MaxWidth × MaxHeight (both 0: no resize) 25 MB, 2560 × 4096, JPEG to WebP on at quality 85, PNG to WebP on from 64 KB
UseDocumentsPreset Size limit, allowed types: PDF, Office documents, plain text, CSV and ZIP 20 MB
UseBinaryAssetsPreset Size limit, allowed types: icons and web fonts 5 MB
UseAnyPreset Size limit only: every type is accepted 20 MB
container.UseDocumentsPreset(preset => preset.MaxSizeInMegabytes = 50);

The allowed types leave out SVG, HTML and scripts, which a browser would run on the host's own address. UseAnyPreset does not: a public read or a read link serves a type outside the module's list as a download, never inline, but a container whose files are read by browsers should not hold such files to begin with.

A container can do without a preset, or add contributors after one; calling an Add…Contributor method again changes that contributor's configuration.

Pictures Stored as WebP

With StoreJpegAsWebp on (the default), the images preset stores every JPEG as a lossy WebP at WebpQuality (1-100, default 85): turned upright by its EXIF orientation, so a phone's portrait photo is not shown on its side, and fitted into MaxWidth × MaxHeight in the same decode.

With StorePngAsWebp on (the default), it stores a PNG as a lossless WebP, fitted into the box the same way: a PNG that already fits keeps every visible pixel, transparency included. A PNG is stored as a PNG when it is smaller than PngWebpMinSizeInBytes (default 64 KB, below which the saving is under about 16 KB), has 16 bits per channel (WebP has 8), or is animated (an APNG would keep one frame). Storing PNGs as WebP gives the reasons.

A GIF and a WebP are stored as they are; a picture still larger than the box - a WebP, a PNG left as one - is resized, upright, unless it is animated. A JPEG or PNG that would still exceed WebP's 16383 pixels once fitted into the box - possible only when MaxWidth or MaxHeight is 0 and the container's decode guard is raised above its default of 8192 pixels - is stored as it was uploaded.

The physical BLOB of a converted picture is named .webp, and the file records image/webp with the size of the WebP. A file stored by id takes the .webp extension in its name too (holiday.jpg becomes holiday.webp), so a download is named for what it is. A file an application saves keeps its name, which is its address: an application that stored covers/holiday.jpg reads it back by that name, and gets the WebP.

Turn either off for a container that must keep those pictures as they are - one whose PNGs are favicons or are sent by email, say:

container.UseImagesPreset(preset => preset.StorePngAsWebp = false);

Changing it does not touch what is stored: pictures stored as WebP stay WebP, and with it off, new ones are stored as uploaded.

Startup Checks

When the host starts, Blob Management checks its containers once more: a default container declared managed stops the host.

Tenant Storage

How much a tenant may store is an ABP feature, set per edition or per tenant with the Feature Management module:

Feature Default
BlobManagement.Enable true Whether the tenant may store files. Turning it off stops storing, and closes the file, directory, container and usage services; it does not close reading what is already public, or a read link already handed out.
BlobManagement.StorageSize 0 The most the tenant may store, in megabytes. 0 is no limit.

Usage is counted from the file descriptors: the size of every file, across every managed container - each file has a BLOB of its own, so the same bytes in two files count twice; soft-deleted files count until their business system deletes them for good - their bytes are stored - and so do files uploaded with a ticket and not confirmed yet. Bytes beyond the allocation are refused with BlobManagement:StorageQuotaExceeded. The check reads the usage and then stores, so two uploads at the same moment can both pass it: it is a soft limit, exceeded by at most an upload each. The allocation is the tenant's only: there is none for a container or a user. What is used is shown on the Usage page.

Errors

Code
BlobManagement:ContainerNotFound The container is not a managed one (HTTP 404).
BlobManagement:BlobAlreadyExists The name is taken and overwriting was not asked for (HTTP 409); the provider turns it into ABP's BlobAlreadyExistsException.
BlobManagement:BlobNotFound No file of that name (HTTP 404).
BlobManagement:BlobManagementDisabled The tenant's BlobManagement.Enable is off.
BlobManagement:StorageQuotaExceeded The tenant's BlobManagement.StorageSize would be exceeded (HTTP 403). An overriding save is checked for the net change: the bytes of the file it replaces count as freed.
BlobManagement:FileAddressedByName The file was saved by an application under its name, and is not renamed, moved or marked public by id (HTTP 409).
BlobManagement:UploadTicketInvalid An upload ticket that is expired, altered or not this Blob Management's (HTTP 403).
BlobManagement:UploadTicketUsed The ticket's file was stored already: a ticket stores one file (HTTP 409).
BlobManagement:FilePending The file was uploaded with a ticket and is not confirmed yet, so it gets no read link (HTTP 409).
BlobManagement:ReadLinkInvalid A read link that is expired, altered or not this Blob Management's (HTTP 403).
BlobManagement:ImageSizeNotSupported An upload asked for a picture size in a container that crops, stretches or pads its pictures (HTTP 400).
BlobManagement:DirectoriesNotAllowed and the other directory errors See Directories.

The container's contributors add their own, which Blob Management's HTTP API answers with the status of what is wrong with the content:

Code HTTP
Dignite.Abp.BlobStoring:ContentTooLarge 413
Dignite.Abp.BlobStoring:ContentTypeNotAllowed 415
Dignite.Abp.BlobStoring:ContentTypeMismatch 400
Dignite.Abp.BlobStoring.Imaging:ImageTooLarge, ImageTooSmall 400
Dignite.Abp.BlobStoring.Imaging:ImageProcessingFailed 422
Dignite.Abp.BlobStoring.Imaging:ImageDecodeTimeout 503

See Also