API Reference: PrimaryMediaAttribute Class

The PrimaryMediaAttribute can be applied to Media-type content model properties. The attribute specifies that this property is the primary media file of the model (in case there are multiple media properties on the model).

If PrimaryMediaAttribute is not specified on any content model property, the first Media property (if any) on the model will be assumed to be the primary media property. The primary media property determines the thumbnail that is shown for the content item in the back office. Also, when creating assets by uploading files in the back office, the uploaded file is set to the primary media property of the content model by default.

Usage

Decorate the model property with the PrimaryMediaAttribute. The attribute does not require any configuration. If PrimaryMediaAttribute is set to a property that is not of type Media, the system will throw a configuration exception at startup.

Example

[Asset]
public class LogoImage: IContentType
{
    // The primary media is used for the thumbnail in the back office.
    [PrimaryMedia]
    public Media LogoOnLightBackground { get; set; }

    // This is the secondary media property.
    public Media LogoOnDarkBackground { get; set; }

    // ...
}