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 -->
<disallowedUploadFiles>ashx,aspx,ascx,config,cshtml,vbhtml,asmx,air,axd,swf,xml,html,htm,svg,php,htaccess</disallowedUploadFiles>
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
}
}
};
}
}
Media upload validation
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?
Jon
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.
Hope this helps,
/Dennis
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:
is working on a reply...