Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Jonathan Roberts 372 posts 1005 karma points
    Oct 26, 2016 @ 11:08
    Jonathan Roberts

    Hi, I would like to restrict CMS users from adding large files to the Media library. Is there an extension i could write to validate files uploaded?


  • Dennis Aaen 4466 posts 18003 karma points admin hq c-trib
    Oct 26, 2016 @ 20:45
    Dennis Aaen

    Hi Jon,

    If you want exclude specific file extensions to be uploaded to the media library then you can add the file extension(s) to the Disallow section in the umbracoSettings.config.

     <!-- These file types will not be allowed to be uploaded via the upload control for media and content -->

    Hope this helps,


  • Casper 69 posts 306 karma points
    Oct 27, 2016 @ 19:45

    In order to cancel out large files, you could go about doing a class that derive from ApplicationEventHandler and hook up to MediaService.Saving event:

    using System;
    using System.Linq;
    using Umbraco.Core;
    using Umbraco.Core.Events;
    using Umbraco.Core.Services;
    namespace App.EventHandlers
        public class AppEventHandler : ApplicationEventHandler
            const int MAX_SIZE = 100000;
            protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
                MediaService.Saving += (sender, e) =>
                    foreach (var entity in e.SavedEntities)
                        var property = entity?.Properties?.First(p => p.Alias.InvariantEquals("umbracobytes"));
                        if (property != null)
                            var size = Convert.ToInt32(property.Value);
                            if (size > MAX_SIZE)
                                if (e.CanCancel)
                                    e.Cancel = true; // todo: explain cancel in notification
Please Sign in or register to post replies

Write your reply to: