How To Configure Episerver So Content Editors Can Upload Media, Images and Assets Within The Editor

One of the cool things about Episerver is that it provides you with a blank canvas to build your website on.  This blank canvas can cause some confusion for people new to Episerver as when people start using the website for the first time, they might see errors/warnings that prevent them using certain media files that you could easily assume should just work.   If a content editor comes up to you and says 'Drag and drop are disabled for content areas' or 'Episerver won't allow me to upload an image' then this guide is for you.

On a brand new blank Episerver website, you will need to specify exactly what page types, blocks, and media the website will use.  Out of the box, if you try to add an image into Episerver you will likely find features, like drag and drop for images within the Episerver editor is disabled.  Luckily, fixing that is very simple, so read on to find out more.

On a brand new blank Episerver website, no media files are enabled by default within the editor.  This is a standard security practice, don't enable anything unless you explicitly enable it.  Luckily, enabling different types of media in Episerver is really quick and easy.  Allowing different types is done with a media descriptor.  Even though it's got a fancy pants complicated sounding name, in reality, you just need to add a few basic classes into your solution and everything will magically work.

What's Going On Under The Covers?

To enable different media formats within your website, you will need to explicitly tell Episerver what to allow.  This is done via writing a few custom C# classes.  When your website first loads, Episerver scans all of your solutions assemblies to find any classes decorated with the [ContentType] attribute. Note, this process works the same for how Episerver reads your page and block type definitions! When it finds a class with a Content Type attribute, it uses reflection to read the classes properties and then adds the contents of the file as an allowed media type.  The default type your class will need to inherit from is the 'MediaData'.  Episerver also has two specialized media types, ImageData and VideoData, which I'm sure you can figure out what they do!  Below, defines the code snippets you'll need to include in your project to enabled PDF's, Images and Videos.

Allowing PDFS

    [MediaDescriptor(ExtensionString = "pdf")]
    public class PdfFile : MediaData

Allowing Images

    [MediaDescriptor(ExtensionString = "jpg, jpeg, jpe, gif, bmp, png, svg")]
    public class ImageFile : ImageData
        public virtual string AltText { get; set; }

Allowing Video

    [MediaDescriptor(ExtensionString = "AVI, FLV, WMV, MOV, MP4")]
    public class VideoFile : VideoData

One of the benefits of using this approach, means as a developer, you can specify the properties that you want content editors to associate with certain files.  As shown above, if you want to allow content editors to add an alt text with any image that they upload, then
and you can simply add in the corresponding property. In the majority of cases, the classes above contains
anything that you need. If you need to do some more advanced stuff, then I suggest you head over to this page.

submit to reddit

Jon D Jones

Software Architect, Programmer and Technologist Jon Jones is founder and CEO of London-based tech firm Digital Prompt. He has been working in the field for nearly a decade, specializing in new technologies and technical solution research in the web business. A passionate blogger by heart , speaker & consultant from England.. always on the hunt for the next challenge

Back to top