Copied to clipboard

Flag this post as spam?

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


  • Colin Anderson 16 posts 107 karma points
    Feb 19, 2021 @ 11:11
    Colin Anderson
    0

    Limit media items to certain types

    I am trying to limit the file types that editors can upload.

    Given that the media library and the entire file upload functionality of Umbraco is lacking big time, I am trying to limit the file types allowed through the MediaService.Saving event.

    I have an event set up that checks the ContentType alias and then checks the file extension. If it is not a PDF then I stop the saving of the content.

    My problem is that most of my users will be uploading the files directly from the Media Picker data type. Is there a way to link the Media Picker to a certain Media Type? The default seems to be Umbraco deciding that anything that isn't an image must then be a File.

  • Mehmet Avcı 55 posts 240 karma points
    Feb 19, 2021 @ 12:43
    Mehmet Avcı
    0

    Hi Colin,

    There is a list of extensions in config/umbracoSettings.config file to limit/allow types. I hope it would be enough for you.

    I believe image types is included in v8 a little different, below are from v7.

     <!-- 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,xhtml,html,htm,php,htaccess</disallowedUploadFiles>
    
    
    
    <imaging>
      <imageFileTypes>jpeg,jpg,gif,bmp,png,tiff,tif,svg,webp</imageFileTypes>
      <!-- If you add a new image file type to umbraco, make sure you update ApplicationEventRegisters.cs IsFileImage method -->
    </imaging>
    

    --Mehmet

  • Colin Anderson 16 posts 107 karma points
    Mar 03, 2021 @ 09:46
    Colin Anderson
    0

    Thanks for the reply, but unfortunately this would limit the files that can be uploaded globally within Umbraco. I want to limit them for a single media picker.

    I have since figured out that the Multinode Treepicker allows me to select the media type I wish to use. Then I can create the customMediaService.Saving event to check a custom config setting to limit the file types.

    Still to be tested, but it should work.

Please Sign in or register to post replies

Write your reply to:

Draft