Copied to clipboard

Flag this post as spam?

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


  • CodeMaster2008 151 posts 184 karma points
    Mar 30, 2011 @ 02:44
    CodeMaster2008
    0

    Hoe to create media from a custom upload control

    Hi;

    I'm creating this custom upload control which I will be using on a custom image gallery/albums.
    Handle the file system (create folder, thumbnail, upload...) is not a problem.

    To better explain what I'm trying to achive here is a brief explanation of how it's going to work:

    A) Each gallery is a sub-node under the "Galleries" node.
    B) A gallery node contains Name, Description and an upload control to allow the user to upload images.
    C) Each gallery has sub-nodes which are images. Images must have names and description.

    What I need to know is how to programatically achieve this:

    1) Since the upload control is being fired on a gallery node, I need to retrieve this node information so I can associate the uploaded images with this gallery.
    2) I also need to create the media(images) programatically.

    I appreciate any help on this.
    Thanks in advance;

  • Alex Skrypnyk 6182 posts 24284 karma points MVP 8x admin c-trib
    Jan 26, 2012 @ 12:36
    Alex Skrypnyk
    0

    Hi everyone,

    We need exactly control ))

    Custom gallery, maybe you could help ?

    Thanks,

    Alex

  • Jeroen Breuer 4909 posts 12266 karma points MVP 5x admin c-trib
    Jan 26, 2012 @ 12:43
    Jeroen Breuer
    0

    With DAMP you can use custom media types. Which will give you full control over what fields a media item has. Watch this video for a demo: http://www.youtube.com/watch?v=LkcObL7CMvQ

    Jeroen

  • Yarik Goldvarg 35 posts 84 karma points
    Jan 26, 2012 @ 13:39
    Yarik Goldvarg
    0

    Try this to upload images.

     public bool Upload(System.Web.HttpPostedFile file)
            {
                string fullFilePath;
                string filename = file.FileName;
                string mediaPath = "";
                //Get Root Id
                Node root = new Node(-1);
                //UmbracoEnsuredPage.CurrentUser
                var media = Media.MakeNew(file.FileName, MediaType.GetByAlias("Image"), new User(0), root.Id);
                //Create folder
                string storagePath = HttpContext.Current.Server.MapPath("/media/" + media.Id);
                System.IO.Directory.CreateDirectory(storagePath);
                fullFilePath = storagePath + "\\" + file.FileName;
                file.SaveAs(fullFilePath);
                 media.getProperty("umbracoBytes").Value = file.ContentLength;
    
                // Save extension
                string orgExt = ((string)filename.Substring(filename.LastIndexOf(".") + 1, filename.Length - filename.LastIndexOf(".") - 1));
                orgExt = orgExt.ToLower();
                string ext = orgExt.ToLower();
                try
                {
                    media.getProperty("umbracoExtension").Value = ext;
                }
                catch (Exception ex)
                {
                    LogManager.Error(ex);
                }
              
                mediaPath = "/media/" + media.Id.ToString() + "/" + file.FileName;
                media.getProperty("umbracoFile").Value = mediaPath;
                media.XmlGenerate(new XmlDocument());
                return true;
            }
  • Jeroen Breuer 4909 posts 12266 karma points MVP 5x admin c-trib
    Jan 26, 2012 @ 13:44
    Jeroen Breuer
    0

    More examples how it's done in DAMP :p.

    In this example you see how the upload datatype is used on a custom page. That way everything will work the same as with the normal uploader.
    BtnCreate_Click method in here: http://damp.codeplex.com/SourceControl/changeset/view/81602#1765786

    In this example you see how I create media if no upload datatype/control is available.
    CreateMedia method in here: http://damp.codeplex.com/SourceControl/changeset/view/81602#1967018

    Jeroen

     

  • Alex Skrypnyk 6182 posts 24284 karma points MVP 8x admin c-trib
    Jan 26, 2012 @ 13:54
    Alex Skrypnyk
    0

    We create big site, with thousands of nodes and galleries, and I think don't use media, for reducing loading of umbraco.

    Maybe mannually create some file structure of images, and cotrol for umbraco admin part for managing images.

  • Jeroen Breuer 4909 posts 12266 karma points MVP 5x admin c-trib
    Jan 26, 2012 @ 13:57
    Jeroen Breuer
    0

    Hmm maybe Umedial is something for you. Most info is dutch but this might help: http://www.slideshare.net/axendo/umedial-umbraco-media-library

    http://www.axendo.nl/nieuws/axendo-presenteert-nieuw-product-umedial

    Jeroen

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies