API Reference: AcceptMediaTypeAttribute Class

The AcceptMediaTypeAttribute can be applied to content model properties of type Media. The attribute sets one or more media (MIME) types that are allowed for files that are uploaded for this property. If a Media type property is not decorated with this attribute, all media types are accepted for file uploads to the property.

Some file formats have multiple media types associated with them. For example, application/zip, application/x-zip and application/x-zip-compressed are all media types for compressed ZIP files. You may need to add them all to the accepted media type list.

Usage

Decorate the content model property with the AcceptMediaTypeAttribute. The attribute constructor accepts one or more string values as a params string[] parameter. Alternatively, the attribute can be set multiple times on the property. If the attribute is set on a property that is not of type Media, an invalid configuration exception will be thrown on startup of the system.

The media type is only validated at the moment of file upload in the back office. If the list of accepted media types changes later, existing files will not be removed or invalidated.

Example

The following example sets 3 accepted media types for the VectorImage asset content model.

[Asset]
public class VectorImage: IContentType
{
    // Restricts accepted media type to vector images.
    [AcceptMediaType("image/svg+xml", "image/x-eps", "application/postscript")]
    public Media File { get; set; }

    // ...
}