Copied to clipboard

Flag this post as spam?

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


  • Vincent Hendriks 13 posts 35 karma points
    Oct 01, 2012 @ 10:11
    Vincent Hendriks
    1

    umbraco 4.9 - default upload / custom media types

    Hi all,

    First of all , i hope i posted this in the correct forum..

    Anyhow, in umbraco 4.9 there's a new upload functionality which makes life a lot easier :)

    However, i like to use custom media types for specific types of images. I usually do this for cropping functionality for certain types of images. Say we have a media type 'ProductImage' which has certain crops specified which normal images don't.

    How does this upload functionality work with these custom media types? Is there any place where i can say for example: upload extensions jpg, png, etc in this folder as media type 'ProductImage'? Or are there any other options I have in order for this to work?

    I hope i've been clear enough..

    Thanks in advance,
    Vincent

     

     

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Oct 01, 2012 @ 11:06
    Jeroen Breuer
    0

    Hello,

    This doesn't work in 4.9. Have a look at this issue: http://issues.umbraco.org/issue/U4-698. I created a pull request for it, but it got rejected: http://umbraco.codeplex.com/SourceControl/network/forks/jbreuer/CustomMediaTypeWebserviceFromJB/contribution/3313.

    Jeroen

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Oct 01, 2012 @ 11:08
    Jeroen Breuer
    0

    I'm currently working on DAMP 3.0 and I will to try to add an uploader in there which works the same as the 4.9 version, but with support for custom media types. Until than you can use this: http://our.umbraco.org/projects/website-utilities/multiple-file-upload/bugs/20286-Support-for-custom-Media-Types.

    Jeroen

  • Vincent Hendriks 13 posts 35 karma points
    Oct 01, 2012 @ 13:56
    Vincent Hendriks
    0

    Thanks for the reply! I'll check it out. I used to 'solve' this by using a custom upload control. Is there a way of disabling this new upload mechanism? Else i'll have customer using this upload causing problems ...

  • jonok 297 posts 658 karma points
    Nov 15, 2012 @ 05:19
    jonok
    1

    Why haven't custom media types been included when creating this new media section interface? Now I have to explain to my client's that although there is an upload button there, you can't actually use it. The media section is where Umbraco falls behind the competition - it's just clunky and needs plug-ins to enhance it, and the plug-ins never quite work right anyway. I get that it's open source software, but it's just annoying that such a great CMS is let down by media management.

  • Flavio Spezi 129 posts 315 karma points
    May 08, 2013 @ 11:27
    Flavio Spezi
    1

    I resolved the problem.

    1. Define custom "Image" media type, with "myCustomImage" alias.
    2. Define custom "Folder" media type; it will can to have "myCustomImage" children only.
    3. Create new file "App_Code/UmbracoMediaFactories.cs" where you will define the custom factory for "myCustomImage".

    This is the "App_Code/UmbracoMediaFactories.cs" code:

    namespace UmbracoMediaFactories {
    public class MyCustomImageMediaFactory : UmbracoImageMediaFactory {
    public override string MediaTypeAlias {
    get { return "myCustomImage"; }
    }
    }
    }
  • jonok 297 posts 658 karma points
    Jul 16, 2013 @ 04:24
    jonok
    0

    Awesome work Flavio, thanks very much!

  • David Dimmer 76 posts 134 karma points
    Aug 23, 2013 @ 18:50
    David Dimmer
    0

    Here is what we used, following Flavio's example and also sharing the using statement.

    We called this file \App_Code\UmbracoMediaFactories.cs

    using umbraco.cms.businesslogic.media;
    
    namespace FyinDotCom.MyCustomFactory
    {
        public class MyCustomImageMediaFactory : UmbracoImageMediaFactory {
            public override string MediaTypeAlias {
                get { return "galleryCrop"; }
            }
        }           
    }
    

    No other code is necessary.

  • Biagio Arobba 16 posts 36 karma points
    Sep 27, 2013 @ 18:37
    Biagio Arobba
    0

    That's great. Thank you.

    I have a follow-up question. I would like the MediaTypeAlias in your example to be different based on the media folder where the media is being uploaded. For example, I have a "gallery" folder, and everywhere else I would like the default media type to be used in uploads, except for the "gallery" folders where I have a "gallery image" type.

  • Flavio Spezi 129 posts 315 karma points
    Sep 27, 2013 @ 23:53
    Flavio Spezi
    0

    Hi Biagio, I haven't sure to understand your question. But I try to answer.

    To obtain a custom folder you need to create a new MediaType that inherits by "Folder" mediaType.

  • Biagio Arobba 16 posts 36 karma points
    Oct 01, 2013 @ 20:38
    Biagio Arobba
    0

    Hi Flavio. I was referring to the code above, this seems to define the default media type for Umbraco, but what if the default media type depends on the folder where someone is uploading images?

    For example, I have a "gallery" folder, and I would like only "gallery images" to go in that folder, but everywhere else I would like the regular "image" media to be created.

     

  • Flavio Spezi 129 posts 315 karma points
    Oct 01, 2013 @ 21:28
    Flavio Spezi
    0

    You can select "Gallery images" Media-type as unique "allowed child nodetype". You can do this with Backoffice: Settings / MediaTypes / "Gallery" nodetype, then "Structure" page of tabstrip.

  • Biagio Arobba 16 posts 36 karma points
    Oct 02, 2013 @ 20:31
    Biagio Arobba
    0

    Right, and I see that and I have done that... but when I go to another folder called "MyOtherFolder"... I don't want to upload gallery images. Instead I would rather upload "Image" images.

  • Flavio Spezi 129 posts 315 karma points
    Oct 02, 2013 @ 22:42
    Flavio Spezi
    0

    Ok, then you will set the right "allowed child nodetype" for "MyOtherFolder".
    I think that there are something that I don't understand the target of issue...

  • Biagio Arobba 16 posts 36 karma points
    Oct 02, 2013 @ 23:29
    Biagio Arobba
    0

    Ok, I was able to get it working for a "gallery" folder only.

    Here is the code:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
     
    using umbraco.BusinessLogic;
    using umbraco.cms.businesslogic.media;
     
    namespace MyCustomFactories
    {
     
        public class MyGalleryImageMediaFactory : UmbracoImageMediaFactory {
     
            public override string MediaTypeAlias
            {
                get
                {
    // The type of media this factory produces
                    return "GalleryImage";
                }
            }
     
            public override int Priority
            {
                get
                {
    // Making sure my factory is earlier in the list of candidate factories (Base class uses 1000)
                    return 500;
                }
            }
     
            public override bool CanHandleMedia(int parentNodeId, PostedMediaFile postedFile, User user)
            {
    // Decide whether this factory applies; If not, another factory will be used (i.e. the base class)
                bool isGalleryParent = false;
     
                if (parentNodeId != -1)
                {
                    Media parent = new Media(parentNodeId);
                    isGalleryParent = parent.ContentType.Alias == "Gallery";
                }
                else
                {
                    isGalleryParent = false;
                }
     
                return isGalleryParent && base.CanHandleMedia(parentNodeId, postedFile, user);
            }
     
        }
     
    }
Please Sign in or register to post replies

Write your reply to:

Draft