Search code examples
umbracoumbraco7

Umbraco: Get ImageCropper & File Upload via SurfaceController


I'm still new to Umbraco 7 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

  • GetCropUrl is an extension method of IPublishedContent so just add using Umbraco.Web; inside your sufrace controller and you should be able to call it. Like this:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using Umbraco.Web.Mvc;
    using Umbraco.Web;  //you are missing this namespace
    
    public class PortfolioSurfaceController : SurfaceController
    {
        // GET: PortfolioSurface
        public ActionResult GetCategoryDetails(int id)
        {
            GalleryItem gItem = new GalleryItem();
            var node = Umbraco.TypedContent(id);
            gItem.imgUrl = node.GetCropUrl("uploadImage", "featured");
    
            return Json(gItem, JsonRequestBehavior.AllowGet);
        }
    }