Copied to clipboard

Flag this post as spam?

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


  • MB 273 posts 936 karma points
    Jul 04, 2016 @ 10:54
    MB
    1

    Get ImageCropper & File Upload via SurfaceController

    Hey everyone!

    I'm still new to Umbraco but I've found my way around Surface Controllers.

    I have created a SurfaceController which you can see future below. But what I can't figure out is how to grab the URL from an Image Cropper and File Upload, I would normally do something like this: @node.GetCropUrl("uploadImage, "thumbnail");

    But that doesn't work inside the controller. How do I achieve this? My end goal is to display the URL in a IMG tag when clicking on a category on this page: http://sp34k.dk/portfolio/vue/ in the description area.

    CODE:

    https://jsfiddle.net/odg3zamx/7/

    SOLUTION: I has help from StackOverflow, It's rather simple. All you have to do is:

    1) Add using Umbraco.Web; 2) You can now grap GetCropUrl

    Example:

    using Umbraco.Web;
    
    namespace Sp34k.Controllers
    {
        public class GalleryItem
        {
            public string projectFile { get; set; }
            public string imgPreviewUrl { get; set; }
        }
        public class PortfolioSurfaceController : SurfaceController
        {
            public ActionResult GetCategoryDetails(int id)
        {
            GalleryItem gItem = new GalleryItem();
            var node = Umbraco.TypedContent(id);
    
       gItem.imgPreviewUrl = node.GetCropUrl("uploadImage", "Thumbnail");
    
            string file = node["uploadProjectFiles"] != null ? node["uploadProjectFiles"].ToString() : string.Empty;
    
            if (!string.IsNullOrWhiteSpace(file))
            {
                gItem.projectFile = file;
    
            }
            return Json(gItem, JsonRequestBehavior.AllowGet);
        }
    }
    }
    
  • Dennis Adolfi 1082 posts 6449 karma points MVP 6x c-trib
    Jul 11, 2016 @ 06:23
    Dennis Adolfi
    0

    Nice job Mike, Thanks for sharing. Will probably be helpful for others! #h5yr!

Please Sign in or register to post replies

Write your reply to:

Draft