Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I have a task to limit the amount of the uploaded files in the particular media folders, but I couldn't find any built-in solution for that in Umbraco CMS.
It should display some message, when user has reached the limit 10 files in the media folder, like "Please delete useless files first" and should prohibit the uploading of the new files.
Is it possible to implement such things?
P.S. Umbraco version 7.12.2 assembly: 1.0.6820.12881
I haven't come across such a scenario. However I can give you some directions based on Casper's post on a related query.
You have to write a custom validation on MediaService.Save event to check for the no of files already in the folder and then showing a message for the user.
I will give it try if i get sometime free over this weekend and let you know.
Thank you Veerapandiyan,
I will look at that solution to check the amount of the files in the folder.
But also would be nice to know the way to display some message user and hide/delete "Upload" button in case when file amount limit was reached.
Which service can achieve that?
Have implemented with the following way:
public class AppEventHandler : ApplicationEventHandler
private const int FileAmountLimit = 3;
private const string MaxAmountReached = "You have reached the Maximum Amount of the files. Please remove other files from the folder before upload.";
/// <inheritdoc />
protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
MediaService.Saving += MediaServiceOnSaving;
private void MediaServiceOnSaving(IMediaService sender, SaveEventArgs<IMedia> e)
var folders = sender.GetByIds(e.SavedEntities.Select(m => m.ParentId));
if (folders.Any(f => f.Children().Count() >= FileAmountLimit))
e.CancelOperation(new EventMessage("File Upload Error", MaxAmountReached, EventMessageType.Error));
And it works like this:
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted