A critical vulnerability was discovered in React Server Components (Next.js). Our systems remain protected but we advise to update packages to newest version. Learn More

Default media type for multiple media types

Vote:
 

We have two media types (GenericMedia & Publication) which inherit media data and have a MediaDescriptor to associate the pdf,doc,docx extensions to both. When a user uploads a file via the asset manager its defaulting to publication but I want it to default to generic media

Ive used this blog post as the basis and would appear to do what I want but in my solution base.GetFirstMatching returns null. Any ideas why?


Snippet

    [ServiceConfiguration(typeof(ContentMediaResolver)) ]
    public class DefaultContentMediaResolver : ContentMediaResolver
    {
        /// <summary>
        /// see http://getadigital.com/no/blogg/resolve-default-media-types-in-episerver/
        /// </summary>
        public override Type GetFirstMatching(string extension)
        {
            var selectedAsDefault = base.GetFirstMatching(extension); //always null?
 
            // For all types inheriting MediaData, I want to use class GenericMedia as default not publication
            if (typeof(MediaData).IsAssignableFrom(selectedAsDefault))
                return typeof(GenericMedia);
 
            return selectedAsDefault;
        }
    }


Snippet

    [ContentType(
        DisplayName = "Publication",
        GUID = "457c2e33-cc01-4653-9958-2726027484dc"]
    [MediaDescriptor(ExtensionString = "pdf,doc,docx")]
    public class Publication : MediaData, ISearchableContent
    {
        public virtual bool ExcludeFromSearch { get; set; }
    }


 Snippet

    [ContentType(
         DisplayName = "GenericMedia",
         GUID = "47DA9013-68A0-4897-BBE7-C83A1F1A9BFD",
         Description = "Used for generic file types such as Word or PDF documents.")]
    [MediaDescriptor(ExtensionString = "pdf,doc,docx")]
    public class GenericMedia : MediaData, ISearchableContent
    {
         public virtual bool ExcludeFromSearch { get; set; }
     }

#172877
Dec 13, 2016 11:31
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.