Assets and media
Assets are ordinary Vox entities with binary content. An image, video or document can therefore have the same metadata, relations, ownership, permissions, history and editorial workflows as other domain data.
For the team workflow, see Replace a product image.
Vox does not prescribe one universal asset class. An application defines the asset types its domain needs and can add fields such as alt text, copyright, dimensions, duration or rendition state:
public interface IMedia : IVoxAsset
{
}
// Without it, the route name would be images, which Vox's own routes use, so startup fails
[VoxRouteName("pictures")]
public class Image : IMedia
{
// IVoxAsset and IVoxEntity properties omitted.
public string? AltText { get; set; }
public string? Copyright { get; set; }
}
public class Product : IVoxEntity
{
public List<VoxReference<IMedia>> Media { get; set; } = [];
}
A relation may target a concrete asset type or an interface shared by several types. Products can consequently refer to images and video through one media relation without giving up the concrete metadata of either asset.
Metadata and content
The entity is the authoritative metadata record. Binary content is stored through a separate content-store
abstraction and streamed with range support. Vox includes a disk-backed implementation, options.UseAssets(), which
stores the files under Vox:Assets:RootPath, or App_Data/assets by default, and an Azure Blob Storage one, see
Azure Blob Storage, while an application can connect another object store or external DAM without
changing the entity and relation model.
Uploading an asset creates its metadata through the asset type's normal create action and stores the content as one
operation from the client's perspective. Its id is in the metadata, eg { "id": "red-shoe" }, or generated when it's
left out, once, before the content is stored under it. An asset type with [VoxRequireId] rejects an upload without
an id before any content is stored. Deleting or purging an asset coordinates removal of its managed content with
the entity lifecycle.
Content types
An asset type can restrict what can be uploaded as it with [VoxAssetContentTypes], eg "application/pdf" or
"image/*"; without it, any file can be uploaded. Content that's stored without a content type, or as
application/octet-stream, which browsers send for files they don't know, eg CAD drawings, gets the content type of
its file name's extension when Vox knows it: manual.pdf is stored as application/pdf and bracket.step as
model/step. This happens before the asset type's content types are checked, so manual.pdf uploaded without a
content type can be a PDF-only document, and it applies to every way content reaches Vox: the API, MCP, imports and
IVoxAssetManager. A content type that's another name of the extension's, which browsers send as the computer has
registered it, eg application/acad for a DWG drawing where AutoCAD is installed, or application/vnd.ms-excel for a
CSV file where Excel is installed, is replaced by the extension's too, so an asset type only needs to list the
registered content types, eg image/vnd.dwg and text/csv. Any other content type the uploader gives is kept as it
is, and an unknown extension stays application/octet-stream.
Replacing content
IVoxAssetManager.ReplaceContentAsync, or PUT api/assets/{type}/{id}/content, replaces the content of an asset and
keeps its id, its other fields and everything that refers to it. The content fields (FileName, ContentType,
Length, StorageKey, Path and ContentRevision) are owned fields without actions: only the asset manager writes
them, but they're part of the owned snapshot of drafts and releases. A replacement in a draft or release, eg
?scope=draft, is published with it, and the published content stays until then.
ContentRevision identifies the bytes: it's the SHA-256 hash of the content, so editing eg alt text keeps it, while a
replacement changes it. Restoring an earlier version from the history keeps the current content, since earlier contents
aren't kept.
Cleanup
An asset can have several stored contents at once: the published one and those of its drafts and releases. Whenever something happens to an asset through Vox, Vox deletes that asset's contents that none of these live states uses, with the thumbnails, renditions and image facts of contents that are gone:
- after its content is replaced, and after a published change of its content or of an image's focal point;
- after it's deleted, which removes its originals, thumbnails, renditions and facts;
- after its draft is discarded or it's removed from a release, eg an editor uploads a better photo in a draft and then discards the draft: the uploaded photo is deleted and the published one stays;
- when the transaction that created or replaced it fails, eg an import that stores a product video and then fails on another record: the stored video is deleted with the rollback.
Nothing runs on a schedule and nothing reads every asset, so the cleanup costs the same with ten assets or ten million. History doesn't keep contents. A content is stored as pending until the asset that uses it is saved, so an upload that's still being saved isn't cleaned up; an abandoned one is, after a day, the next time the asset is cleaned up. A delete in a release keeps the published content until the release is published.
Some files stay until the asset's content is next replaced, or for good:
- the uploads of a content release that's deleted without being published, eg a cancelled campaign that replaced 300 product images keeps those 300 files;
- the old content kept for a scheduled restore that's unscheduled;
- an upload left by a host that stopped between storing and saving it, and a cleanup that failed after its transaction committed; for a new asset that was never saved, nothing removes it;
- the thumbnails and renditions of an original that was deleted outside Vox, eg in the Azure portal. The asset shows as broken, see Broken assets;
- thumbnails and renditions made by an earlier image processor or thumbnail recipe, after a Vox upgrade that changes them, until the image's content changes. See Storage of image data for how to remove them.
Each application has an asset root, or container, of its own. The cleanup deletes every content of an asset that its own database doesn't use, so two applications sharing one asset root, eg a PIM and a CMS on the same file share, would delete each other's original files when they have an asset of the same type and id, and nothing can rebuild those.
A custom IVoxAssetContentStore stores, lists and deletes the contents of one asset at a time: Vox never lists every
asset, so a store needn't be able to. Its OpenReadAsync returns null for a key it has no content for.
Broken assets
A broken asset is one whose stored content is missing, eg a file that was removed from an object store by hand. Vox reads the content only when it's asked for, so it shows such an asset like any other, and reports its content as missing where it's read:
- The content endpoint,
api/assets/{type}/{id}/content, returns 404, andIVoxAssetManager.OpenReadAsyncnull. - Image renditions and thumbnails return 404, so a projection's image URL of it doesn't load.
- A subscription's download URL returns 404 until the content is replaced.
- MCP's
get_asset_contentreports that the content isn't stored when it's read inline. - The admin shows a placeholder for an image that doesn't load, and a file by its kind, eg a PDF, whose link opens to a "not found".
An importer that brings the metadata of files before the files themselves, eg a PIM whose files are downloaded on
demand, creates broken assets on purpose with IVoxAssetManager.CreateWithMissingContentAsync. It takes the file name,
content type and length of the asset and checks the content type like an upload does. It stores nothing: the storage
key is one that no content store has, and the content revision a placeholder. The asset is published like any other,
so subscriptions, projections and MCP see it. Replacing its content with ReplaceContentAsync makes it a normal asset,
and publishes a change with a new content revision, so subscribers and projections catch up. Create broken assets only
while nothing that's told of a new asset relies on reading its content; an asset uploaded with its content is never
seen without it.
Images
CommerceMind.Vox.Images makes image assets available as public renditions: resized, cropped, padded and converted
JPEG, PNG and WebP made on the first request from the original and stored for later requests. They're made of JPEG, PNG,
WebP and TIFF originals, so the TIFF masters of product photos are delivered and shown in the admin like any other image.
It makes them with SkiaSharp, and reads TIFFs with LibTiff.NET: the first page of a file, in RGB, CMYK, grayscale or a
palette, at 8 or 16 bits, without its color profile. An application that registers an IVoxImageProcessor of its own
replaces SkiaSharp. MapVox() serves the renditions at /images:
builder.AddVox(options => { /* ... */ })
// Renditions under Vox:Images:RenditionRootPath, or App_Data/renditions; a CDN at Vox:Images:PublicBaseUrl
.AddVoxImages(images =>
{
images.AddProfile("product-card", profile =>
{
profile.Widths = [320, 640, 960];
profile.SizeMatching = VoxImageSizeMatching.RoundUp;
profile.AspectRatio = 1;
profile.Fit = VoxImageFit.Cover;
profile.Format = VoxImageFormat.Webp;
profile.Formats = [VoxImageFormat.Jpeg];
});
});
Enabling images makes every image asset public as renditions of the profiles, without a user or token; exclude asset
types with Exclude<T>(), or leave images disabled and synchronize selected images elsewhere when only some may be
public. The original-content endpoint stays as private as it was.
Exclude asset types that hold no images too, eg documents and videos: the image endpoint answers a request for one of
their ids with a redirect when the id exists and 404 when it doesn't, which tells anyone which ids exist.
Each application has a rendition store of its own: two applications sharing one rendition directory or container would clean up and
trim each other's renditions, and each deployment of one would rebuild the image URLs of the other.
Profiles and URLs
A request names a profile, which defines the fit (Contain, Cover around the focal point, or Pad), size, format,
quality and background, and the finite alternatives a request may choose. Without alternatives a request can only ask
for the profile itself. Sizes can be exact widths, heights or pairs, buckets that round up to the next allowed size, or,
when a host explicitly allows it, bounded arbitrary sizes. Images are never enlarged: a size above the original gives a
smaller rendition with the requested proportions.
/images/pictures/hero.webp?profile=product-card&w=640&v=Qm9c...
VoxImageUrls makes canonical URLs with the current cache buster v, a fingerprint of the original's revision, the
effective recipe, the focal point when it crops, and the processor. A request that isn't canonical, eg a width that's
rounded up or a missing v, is redirected to the canonical URL. A request with an earlier v gets the current
rendition of its recipe: v only makes caches fetch it again, and old renditions aren't kept.
Canonical responses have Cache-Control: public, max-age=31536000 and an ETag of their bytes. CDNs must include the
whole query string in their cache keys. Unknown, duplicate and disallowed parameters are rejected, and redirects and
errors aren't cached for long.
Descriptive paths
CommerceMind.Vox.Images.Routing delivers images at the paths they publish as routes, with Vox.Routing. An ordinary
route projection publication of the image type claims paths in the image space, media by default, without extensions:
builder.AddVox(...)
.AddVoxRouting()
.AddVoxImages(...)
// MapVox() serves eg /media/running-shoes/red-trail-shoe.webp?profile=card&w=640&v=…
.AddVoxImageRouting(images => images.Space = "media");
The extension selects the format, so one route serves every format. VoxImageRouteUrls makes URLs at the canonical
path, or the technical one without a route. Aliases deliver the image at their own path, and a changed slug redirects
the old path with the validated image parameters only. Routes are addresses, not permissions: every image also has its
technical URL.
URLs in projections and on sites
VoxImageUrls.GetDescriptor and VoxImageRouteUrls.GetDescriptorAsync return what a site needs to show an image with
a profile: its URL, its URLs at each width of the profile, and the same in the other formats. Store them in delivery
projections; voxImageUrl, voxImageSrcSet and voxPictureSources of @commerce-mind/vox-web read them, rounding
widths up the way the endpoint does. A projection that makes URLs is made again when the image is replaced, its focal
point moves, its route changes, or its profile, the processor or the public base URL changes: once a deployment is
active, one of its hosts compares the fingerprints of the profiles with those stored by the last deployment and records
each change once. Routed URLs aren't part of those fingerprints, so after changing
VoxImageRoutingOptions.PathPrefix or Space, rebuild the delivery projections that hold routed URLs.
Facts and admin
The facts of an image, its format, size as it's shown, transparency and frames, are read from its bytes when it's uploaded or replaced, and from existing ones when they're first requested, and kept by content revision. Map them into fields of the asset, which are saved with the content:
images.MapFacts<Image>((image, facts) => (image.Width, image.Height) = (facts.Width, facts.Height));
GET api/images/{type}/{id}/facts returns them. The admin UI shows thumbnails of the vox-thumbnail profile instead
of originals, previews of drafts and releases, and edits the focal point of an IVoxImageAsset on the image, with
coordinate inputs and a reset to the center.
Previews, focal points and deletion
Assets that implement IVoxImageAsset have a focal point, an owned field edited like any other. Moving it changes the
renditions that crop around it, never the original. GET api/images/{type}/{id}/url?profile=...&scope=draft returns a
preview URL of the image in a draft or release, for principals that may read it there, whose responses aren't stored.
The preview URL carries its scope, and so do the URLs of the admin's thumbnails.
A deleted image has no renditions, also when they're still stored: every request reads the current state of the image first. Existing CDN and browser copies stay until they expire. Renditions and facts of replaced originals are removed with the cleanup of the asset's content.
Storage of image data
Thumbnails, renditions, facts and settings are kept under Vox:Images:RenditionRootPath, or in blob storage, see
Azure Blob Storage, in folders of their own:
thumbnails/{hh}/{hash}/{fingerprint}.webp the admin's thumbnails, of the vox-thumbnail profile
renditions/{hh}/{hash}/{fingerprint}.jpg every other profile, as .jpg, .png or .webp
facts/{hh}/{hash}/{revision}.json the facts of each content revision
settings/profiles the fingerprints of the profiles
On disk each image file has a .json file of its information next to it. An asset's folder, {hh}/{hash}, is named by
a hash of its type and id.
Renditions are trimmed to RenditionStorageLimit, 10 GiB by default, on disk, least recently read first, and made again
when they're asked for. Thumbnails are never trimmed: one is made per image content and width the first time the admin
shows it, and stays until the image's content changes or the image is deleted. A thumbnail is 3 to 60 KB, so an image
seen in the admin at one or two sizes takes about 30 to 90 KB, and a million such images about 30 to 90 GB. Images that
nobody opens in the admin have none. A profile of your own with the same recipe as vox-thumbnail gets renditions of
its own.
Thumbnails and renditions can be deleted at any time, eg to reclaim the space of those made before an upgrade that
changed the thumbnails or the image processor: the next request makes each one again. Delete the thumbnails or
renditions folder below the rendition root, or the blobs below that prefix:
az storage blob delete-batch --account-name retailerassets --source vox-assets --pattern "thumbnails/*" --auth-mode login
Don't delete the whole rendition root or container. Without settings/profiles, the next deployment counts every
profile as changed and makes every projection that holds image URLs again, which takes a while with millions of
products.
Limits
Originals of at most 25 MiB, 40 megapixels and 16,384 pixels per side, and renditions of at most 4,096 pixels per side
and 16 megapixels, are made by default, two at a time per process, with a bounded queue and a 15 second deadline. A
rendition that would be larger, eg of a profile without a size or a request for a width only of a tall image, is scaled
down to fit: w=1000 of a 1,000 × 16,000 image gives 256 × 4,096. GIF,
SVG, animations and other formats are rejected. A TIFF original counts its full size, so a large uncompressed master may
be above 25 MiB: raise Limits.MaxSourceBytes for those. Apply rate limiting to the image endpoints, under /images,
and in the CDN, since requests for renditions that aren't stored decode images.
CommerceMind.Vox.Images brings SkiaSharp with its native libraries for Windows and macOS. Linux hosts add
SkiaSharp.NativeAssets.Linux, or SkiaSharp.NativeAssets.Linux.NoDependencies in containers without fontconfig, of
the same version as the SkiaSharp that CommerceMind.Vox.Images references.
Azure Blob Storage
CommerceMind.Vox.AzureBlob stores the original files of assets in an Azure Blob Storage container instead of on disk,
so every instance of an application shares them. CommerceMind.Vox.Images.AzureBlob keeps thumbnails, renditions,
facts and settings there too:
builder.AddVox(options => { /* without UseAssets() */ })
.AddVoxAzureBlobAssets(blobs =>
{
blobs.ServiceUri = new Uri("https://retailerassets.blob.core.windows.net");
blobs.Credential = new DefaultAzureCredential();
blobs.ContainerName = "vox-assets";
})
.AddVoxImages(images => { /* profiles */ })
// In the assets' container, or another: renditions => renditions.ContainerName = "vox-images"
.AddVoxAzureBlobRenditions();
Give either a ConnectionString, eg for Azurite in development or an account key, or a ServiceUri with a
Credential, eg a managed identity, which comes from the Azure.Identity package and is set in code. They can be
configured as Vox:Assets:AzureBlob:ConnectionString, ServiceUri and ContainerName, and the rendition store's as
Vox:Images:AzureBlob:*. The rendition store uses the assets' account and container unless it's given others, and needs
an account of its own when the originals are on disk. Vox refuses UseAssets() and AddVoxAzureBlobAssets together.
Vox doesn't create the container, so that its identity needs no role on the whole storage account. Create it once, and
keep it private: originals are served only through Vox's endpoints, with Vox's permissions, and renditions through
/images, which checks the image's current state first.
az storage container create --account-name retailerassets --name vox-assets --auth-mode login
The identity needs the Storage Blob Data Contributor role on the container. A request against a container that doesn't
exist fails with Azure's ContainerNotFound error rather than showing assets as broken. Timeouts, throttling and server errors are retried by the Azure SDK, and then
count as transient errors that Vox's background work retries.
Originals are stored below originals/, the image data in the folders of Storage of image data.
Blob names are made of a hash of the asset's type and id and a random name per content, never of the uploaded file name.
One container or two
One container is the simple default, and Vox keeps originals and image data apart in it by their prefixes. A second
container for image data, eg vox-images, is worth it when:
- someone may delete thumbnails, eg in a test environment, but mustn't touch originals: Azure grants access to a whole container, not a prefix;
- only the originals are backed up, since image data is made again from them;
- you want to rule out that a bulk delete with a wrong pattern, eg
delete-batchwithout--pattern, deletes originals.
Lifecycle rules and access tiers work by prefix, so they work the same either way. To move image data to a second
container later, copy settings/profiles to it, set ContainerName, restart and delete the old prefixes; thumbnails and
renditions are made again, and facts read again from the originals. Without the copied setting, the first deployment
makes every projection with image URLs again.
Lifecycle rule for renditions
Blob storage keeps no cheap record of when a blob was last read, so Vox doesn't trim renditions there. Add a lifecycle
management rule that deletes blobs below renditions/ some time after they're created, eg 30 to 90 days: a deleted
rendition is made again on its next request. It matters most for profiles with AllowArbitrarySizes, since anonymous
requests can make a rendition of every allowed width. Don't add a rule for thumbnails/, facts/, settings/ or
originals/.
Exporting originals
Subscriptions deliver the original files of assets as download URLs that don't expire, eg the images of the products in an ecommerce channel, without public image delivery: see Asset files. An image is in the channels of the products that use it when it inherits its membership through the inverse of their media relation, see Contexts.
Admin UI
The generic Admin UI discovers asset types, accepted content types and create-action fields from model metadata. It
lists an asset type as a gallery when its content types can hold images, the same rule as for fields below, or videos,
and as a table when they only hold other files, eg PDFs and Office documents, with each file's icon, file name and size,
since a tile of such a file only shows its icon. [VoxView] sets another view, and each person can pick one for themselves. It can also
use a referenced asset as the image for another entity's card or list entry.
Each asset is shown as what it is. An image (JPEG, PNG, WebP, GIF, AVIF, SVG or TIFF) is shown by its thumbnail, or by the
file itself when it has none and the browser can show it; a TIFF without a thumbnail, eg on a host without
CommerceMind.Vox.Images, is shown by the placeholder of an image. Any other file, including images the browser can't
show that aren't pictures as such, eg Photoshop or camera raw files, is shown by the icon
of its kind with its title, eg a PDF as a document with a red band labelled PDF. The kinds are PDF, word processing,
spreadsheet, presentation, plain text, data and markup, archive, video, audio, design and print, CAD, 3D model, font,
and any other file. The kind comes from the asset's content type, then from its file name's extension. A reference
read with titles carries the contentType and fileName of its asset for this, also nested in lists and dictionaries
and in _keyTitles; when they aren't known, eg for an asset the user may not read, the asset type's content types
decide.
An asset type's content types also decide how a field of it is laid out, before it has values. A field whose target
types can hold images, ie their content types include an image, eg image/* or image/tiff, or they have none, is a gallery
of thumbnails, eg List<VoxReference<IMedia>>. A field of types that only hold files, eg
List<VoxReference<Document>> where Document only allows PDFs and Office documents, is a list of file cards with
their icons and kinds, reordered by dragging, and a single file is a row with its icon, title and kind. A type that
allows any file holds images and files side by side, so its field is a gallery where files show as icon tiles. Files
are chosen and uploaded in the same media picker as images.
In a list of objects or a dictionary, eg a product's images that each say which color they show, an asset in a row is
a compact button with a small thumbnail or file icon and its title. A list whose objects have exactly one asset field,
eg List<ProductImage> with ProductImage.Asset, and a dictionary whose keys are assets, can add a row per asset by
picking several assets in one go. When an object's assets play fixed roles, eg a main and a hover image, model the
roles as an enum key, eg Dictionary<MediaRole, VoxReference<IMedia>>, which is edited as a dropdown.
An image that pictures an entity in lists, set on a list in its layout,
eg layout.Image(product => product.Content.Media), is the first image in the list, so a product whose media is only a
video and a PDF has no image in lists rather than a broken one.
Uploading from the asset list
Create on an asset list opens an upload screen: a drop zone for one or several files, whose browse dialog offers the content types the asset type accepts, and the fields of the asset type's create action with their create defaults. The fields are set once and apply to every file, eg the copyright and tags of a photo shoot. Focal point fields are left out, since they can only be set on an uploaded image. The files upload one after the other with a progress row each; a file that fails, eg a dropped file of a content type the asset type doesn't accept, is listed with its error and the others still upload, while a value the API refuses, eg an alt text that's too long, stops the upload and is shown on its field. An asset type that requires an id on create takes one file at a time, since the id is typed on the screen. With one file, the new asset opens; with several, the list opens in the folder they were filed in. Assets are created in published content, as every upload is, also when a draft or release is selected.
Folders and tags
Vox imposes no DAM taxonomy: folders and tags are entity types the application declares, like any other, and they can carry what the application needs, eg an owner or channel membership. Two attributes tell the Admin UI which field of an asset type holds its folder and which its tags:
[VoxTree]
public class AssetFolder : IVoxEntity
{
// IVoxEntity properties omitted.
[Required]
public virtual string Name { get; set; } = "";
public virtual VoxReference<AssetFolder>? Parent { get; set; }
}
public class AssetTag : IVoxEntity
{
// IVoxEntity properties omitted.
[Required, VoxSearchable]
public virtual string Name { get; set; } = "";
}
public class Image : IMedia
{
// IVoxAsset and IVoxEntity properties omitted.
[VoxAssetFolder]
public virtual VoxReference<AssetFolder>? Folder { get; set; }
[VoxAssetTags]
public virtual List<VoxReference<AssetTag>> Tags { get; set; } = [];
}
The attributes go on the asset class's own property: one on a property of an interface the asset implements, eg
IMedia, isn't read, like Vox's other field attributes. Both are opt-in: a reference from an asset to a tree, eg a buying guide's product category, isn't turned into folders
unless it's marked. Several asset types can share a folder and a tag type, eg pictures, videos and documents filed in
the same campaign folder. A folder is a reference to an entity rather than a path, so renaming or moving a folder is one
write to the folder, not a write to every asset in it.
Vox checks the attributes at startup and stops with a message naming the property when one is misused:
| Attribute | Allowed on | Refused |
|---|---|---|
[VoxAssetFolder] | A single VoxReference<T> at the top level of an asset type, where T is a tree | A type that isn't an asset, a list or a property inside a value, a target that isn't a tree, more than one per asset type |
[VoxAssetTags] | A List<VoxReference<T>> at the top level of an asset type | A type that isn't an asset, a single reference, a property inside a value, an index-backed IVoxRelationReferences<T>, more than one per asset type |
An asset has a handful of tags, which are edited as one value, so the tags are a list; an index-backed relation is
meant for relations with thousands of references. The entity type model names the relations as assetFolder and
assetTags, eg "assetFolder": "folder".
With a folder, an asset type's list in the Admin UI shows:
- A folder pane beside the list with All, Not in a folder and the folder tree, and a breadcrumb such as
"Documents / Manuals" above it. On a narrow screen the pane is a Folder chip. A folder shows the assets filed directly
in it, like a file explorer, and is part of the list's address, so it can be bookmarked and the back button returns
to the previous folder. The list's queries are ordinary filters,
relation.folder=<id>andfolder[null]=true, on the reference that every relation can be filtered by. - Create files the new assets in the folder the list shows, eg uploading in Documents / Manuals files every new document there.
- Move to folder…, which moves the checked assets in one batch update and lists those that fail, eg one someone else changed in the meantime. It works on checked assets, not on "select all matching". On an authored asset type the move is written to the selected draft or release like any edit.
With tags, the field is edited as a tag input with suggestions as you type, the tag filter is shown up front, and the list's selection gets Add tags… and Remove tags…, which skip the assets that already have, or don't have, the tags. When the tag type's create action needs nothing but its title field, and the person may create tags, typing a tag that doesn't exist offers to create it. Make the tag type searchable, as above, so suggestions are searched rather than matched among the first hundred tags.
The media picker shows the same folder pane and tags, and uploads into the folder that is picked; its filter chips are the list's, so a picker can also be narrowed by any other reference of the asset type. Folders and tags themselves are created, renamed and moved on their own lists.
See Entities and relations, Editor metadata and selections and History and audit.