Copied to clipboard

Flag this post as spam?

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


  • Jin Botol 134 posts 287 karma points
    Jun 05, 2017 @ 08:33
    Jin Botol
    0

    How to get the image url from Image Cropper and display in Surface Controller

    I want to get the image url from image cropper, first I've replaced the default File upload property with an Image cropper property on my Image media type, and I'm using multiple media picker in my content node. I want to get the url of those images in my surface controller.

    What I did is:

    var searcher = new IndexSearcher(indexDirectory, true);
    
    var masterQuery = new BooleanQuery();
    
    TopDocs resp = searcher.Search(masterQuery, null, searcher.MaxDoc());
    
    foreach (var scoreDoc in resp.ScoreDocs) {
        var document = searcher.Doc(scoreDoc.doc);
        var docsId = Umbraco.TypedContent(Convert.ToInt32(document.Get("id")));
        var imageList = docsId.GetPropertyValue<string>("images").GetCropUrl(width: 329, height: 200);
    }
    

    but it gives me error:

    'Cannnot implicitly convert type 'string' to 'System.Collections.Generic.List'

    I've already watch the EP30 of Jeavon, but he didn't include on how to display it in SurfaceController

    Anyone can help with me, I'm stuck

    Jin

  • John Bergman 483 posts 1132 karma points
    Jun 05, 2017 @ 16:39
    John Bergman
    0

    If it is 7.6 or newer try this

    var imageList = docsId.GetPropertyValue

  • Jin Botol 134 posts 287 karma points
    Jun 06, 2017 @ 01:49
    Jin Botol
    0

    Hi John,

    Thank you for reply, I've use 7.5.6.

    I got an error.

    An exception of type 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' occurred in System.Core.dll but was not handled in user code

    Additional information: 'string' does not contain a definition for 'FirstorDefault'

    My Controller:

        foreach (var scoreDoc in resp.ScoreDocs) {
           var document = searcher.Doc(scoreDoc.doc);
           var docsId = Umbraco.TypedContent(Convert.ToInt32(document.Get("id")));
           var imageList = docsId.GetPropertyValue<string>("images").GetCropUrl(width: 329, height: 200);
    
           var product = new Product()
           {
                  Images = imageList
           } 
         }
    

    My Model:

    public class Product
    {
           public string Images { get; set; }
    }
    

    Jin

  • John Bergman 483 posts 1132 karma points
    Jun 06, 2017 @ 04:02
    John Bergman
    0

    OK, sorry (my bad). The issue is the property images is a string, not a media item. GetCropUrl assumes you are working with media.

    Take a look at a package called Slimsy, I think that will do what you want to do.

  • 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.

    Continue discussion

Please Sign in or register to post replies