Copied to clipboard

Flag this post as spam?

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


  • Alex Perotti 53 posts 94 karma points
    Feb 04, 2014 @ 10:02
    Alex Perotti
    0

    Upload custom media from folder (umbraco 6.x)

    Hi all,

    I have 2 custom media types: a custom folder type that inherits folder and a custom image type that inherits from image.

    The purpose is to put some costraints for the editor and have some custom resize based on the image type.

    My problem is related with multiple upload: when I upload images from the custom folder it fails to create the custom image (I suppose it tries to create standard images and fails because they're not allowed as children).

    How can I extend the multiple upload feature? Thank you

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Feb 04, 2014 @ 12:04
    Jeroen Breuer
    0

    Hello,

    I don't know how to extend the default multiple upload feature, but you can disable it and replace it with a custom version of MFU: http://our.umbraco.org/projects/website-utilities/multiple-file-upload/bugs/20286-Support-for-custom-Media-Types

     

    I've also done that in the DAMP Gallery.

    Jeroen

  • Alex Perotti 53 posts 94 karma points
    Feb 04, 2014 @ 12:07
    Alex Perotti
    0

    Thank you for the feedback :)

  • Dejan Stojanovic 12 posts 51 karma points
    Mar 18, 2014 @ 08:22
    Dejan Stojanovic
    1

    There is a pretty simple workaroud for this, but you will have to do some coding :)

    As much as I tried to change behaviour of mass uploader, nothing worked, so I decided to do some work right after upload.

    In your Application handler constructor, add a handler for MediaService.Saved event like the following:

     public class ApplicationHandler : ApplicationEventHandler
    {
    public ApplicationHandler()         {             MediaService.Saved += new Core.Events.TypedEventHandler<IMediaService, Core.Events.SaveEventArgs<IMedia>>(MediaService_Saved);         }
    } 
            void MediaService_Saved(IMediaService sender, Core.Events.SaveEventArgs<IMedia> e)
            {
                foreach (IMedia mediaItem in e.SavedEntities)
                {
                    if (mediaItem.ContentType.Alias.Equals("Image"StringComparison.InvariantCultureIgnoreCase) && mediaItem.Parent() != null && !mediaItem.Parent().ContentType.Alias.Equals("Folder"StringComparison.InvariantCultureIgnoreCase))
                    {
                        var firstCustomType = mediaItem.Parent().ContentType.AllowedContentTypes.Where(t => !t.Alias.Equals("Image"StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();
                        if (firstCustomType != null)
                        {
                            IMediaType newType = ApplicationContext.Current.Services.ContentTypeService.GetMediaType(firstCustomType.Alias);
                            if (mediaItem.ContentTypeId != newType.Id)
                            {
                                mediaItem.ChangeContentType(newType, true);
                                ApplicationContext.Current.Services.MediaService.Save(mediaItem, 0, false);
                            }
                        }
                    }
                }
            }

    Your folder where you want to upload custom images needs to allow both images and custom image types. This way uploader will not block images to upload and this code will do the magic after upload.

    Basically it changes normal image type to custom image type. Limitation is that this works only if you need one custom image type because it takes first one which is not Image. If you need to support multiple custom types for mass upload you will have to do saom small rework of this code.

    Please let me know if this works for you.

  • Brendan Rokebrand 7 posts 131 karma points
    Apr 10, 2014 @ 19:45
    Brendan Rokebrand
    0

    @ Dejan you're a legend

    Code worked exactly as is, I'm creating different media image types with different crops, this works amazingly well

  • Yuri Derevianko 7 posts 27 karma points
    May 22, 2014 @ 15:46
    Yuri Derevianko
    0

    Works like a miracle! Thanx!

Please Sign in or register to post replies

Write your reply to:

Draft