Copied to clipboard

Flag this post as spam?

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


  • Arun P K 11 posts 72 karma points
    Jul 09, 2016 @ 21:02
    Arun P K
    0

    Multiple Media Pickers with 1 to 1 mapping to respective croppers

    Hi Folks,

    I was wondering if we can create multiple Media pickers which maps to specific Image Croppers. I am working on a project wherein I am trying to segregate the whole Architecture to be components based.

    For Example Let us assume I have a "Media Picker for Icons upload / selection from a specific Media folder with Icon MediaCroppers setup for it". Can this use case be achieved in any way?. Similarly I am planning up for other regions of the site.

    Can I play around with Custom Media Types for each of the Media Picker mapped to specific Image Cropper?

    Please guide me, Thanks in Advance.

    Thanks, Arun P K

  • Ian 178 posts 752 karma points
    Jul 10, 2016 @ 00:28
    Ian
    0

    I think you can in effect achieve what you are after as an example icons would need to live in a designated media folder prescribed using the umbraco 'structure' rules to only allow your icon media type. Your media picker would need to have the icon media folder as its start node.

    You would then register a handler for the mediaservice.saving or saved event (can't remember which one i used). In the function you would check if this is a new entity and if the folder being uploaded to (its parent) is the icon folder you would chang the media type from image (default) to your icon media type. Then you know all media items for this picker will have the crop you want

  • Arun P K 11 posts 72 karma points
    Jul 11, 2016 @ 21:54
    Arun P K
    0

    Hi Ian,

    First of all thanks for replying quickly.

    I started trying your approach. I am not that familiar with Umbraco Services. It would be great to know how I can compare the current saving images folder with the parent folder on which the media saving was invoked.

    I am able to hook into MediaService Saving and get the SavedEntities as well. Now the major concern is how I will figure out where this service was invoked if its only for "Icon Media Picker" or not. If its from "Icon Media Picker" then how will I be able to map that to already created "Icon Media Type" on the fly by using its alias.

    Thanks in Advance.

    Arun P K

  • Ian 178 posts 752 karma points
    Jul 11, 2016 @ 22:56
    Ian
    0

    Ill get you a copy of my code tomorrow. In the meantime the important thing to note is that in the mediaservice save event you wont make a direct reference to the picker itself at all. What you do is grab the save entity parent property and check if the media type alias of this parent equals iconfolder for example and then changecontenttype to your desired type using the alias eg "icon" as the argument. Where the picker comes in is that as you've set the start node to your icon folder you know that any image uploaded when using that picker is going to end up in the icon folder.

    Hope that makes sense

  • Ian 178 posts 752 karma points
    Jul 12, 2016 @ 10:48
    Ian
    100

    this is my code

    private void MediaService_Saving(IMediaService sender,
            SaveEventArgs<IMedia> e)
        {
            foreach (var item in e.SavedEntities)
            {
                if (!item.HasIdentity)
                {
                    var mediaParent = sender.GetById(item.ParentId);
                    if (mediaParent == null)
                        continue;
    
                    if (mediaParent.ContentType.Alias.Equals("DocumentThumbnailFolder"))
                    {
                        var documentThumbnail =
                            ApplicationContext.Current.Services.ContentTypeService.GetMediaType("DocumentThumbnail");
                        if (documentThumbnail == null)
                            continue;
    
                        item.ChangeContentType(documentThumbnail);
                    }
    
                }
            }
        }
    
  • Arun P K 11 posts 72 karma points
    Jul 13, 2016 @ 05:57
    Arun P K
    0

    Hi Ian,

    Thanks a lot pal, I was able to get it working. Now I am confident enough to play around with Media Picker, Image Croppers and Media Types.

    Your Guidance helped me out to understand things pretty fast. Thanks a lot once again :).

    Thanks,

    Arun P K

Please Sign in or register to post replies

Write your reply to:

Draft