logo
logo

Renditions

The SDK allows getting rendition information and downloading the rendition binaries.

Warning

Renditions are not supported in the Scripting SDK.

Getting renditions

Getting a rendition is done trough the entity object (IEntity ). Not all entities support renditions, but for example M.Asset does.

The renditions can be accessed through the IEntity.Renditions property, which returns a list of IRendition objects. The rendition consists of the rendition's name and its rendition items. By default, an asset's renditions are named like this (but can be customized):

  • "bigthumbnail"
  • "downloadAlternative"
  • "downloadOriginal"
  • "downloadPreview"
  • "metadata"
  • "pdf"
  • "preview"
  • "thumbnail"

The number of rendition items (IRendition.Items) depends on the file and the rendition. An image could be processed to one or multiple items. For example, there could be an item per layer in the image. A PDF file can have a rendition item per page.

Entities that don't support renditions return an empty list of renditions.

Downloading renditions

Downloading renditions can be done through the IRendition and IRenditionItem objects. The rendition can be downloaded manually by using the Href property of the IRenditionItem object, but it also supports downloading directly to a specified filepath or as a stream.

In the following example, the first rendition item of the original file (named "downloadOriginal") is downloaded from the asset with the id 8626. The directory variable is the folder where the rendition will be saved.

var asset = await MClient.Entities.GetAsync(8626);
var original = asset.GetRendition("downloadOriginal");
var rendition = original.Items.FirstOrDefault();

if (rendition != null)
{
    var filename = asset.GetPropertyValue<string>(Constants.Asset.FileName);
    var directory = @"C:\Users\Stylelabs\Desktop";
    var filepath = Path.Combine(directory, filename);
    await rendition.DownloadAsync(filepath);
}
Note

The asset needs to processed before renditions can be used in the SDK. When the asset is not processed yet, the IEntity.Renditions property will be empty. The status of the renditions can be checked on the assets property named "Renditions", which contains a JToken.

Can we improve this article ? Provide feedback