Copied to clipboard

Flag this post as spam?

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


  • jonny cundall 15 posts 157 karma points
    Nov 10, 2018 @ 20:30
    jonny cundall
    0

    Hi I am trying to get a site to work after having lost and recreated some of the source files, using the deployed site files. I have everything working on my local dev machine except for one thing: any image which is a media picker property does not display.

    typically these are using

     @Umbraco.Media(CurrentPage.mainImage).GetCropUrl("LargeSquare")
    

    and I know this should work, as it does on the deployed site, but when I inspect the html the src url for the image is blank. This also happens if I omit the crop part of the url

    I've tried rebuilding the indexes, publishing some items, but nothing has worked yet. I'm not sure where to look for the source of the problem.

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Nov 11, 2018 @ 21:38
    Alex Skrypnyk
    0

    Hi Jonny

    Try to check what is in "CurrentPage.mainImage" property? Is there a valid media id?

    Thanks,

    Alex

  • jonny cundall 15 posts 157 karma points
    Nov 12, 2018 @ 13:11
    jonny cundall
    0

    yes there is a valid media id

    also If I construct the url manually using the Id the image gets served.

    the issue is just that @Umbraco.Media is not able to construct the url

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Nov 12, 2018 @ 14:18
    Alex Skrypnyk
    0

    Hi Jonny

    Try this code:

    var mediaItem = Umbraco.TypedMedia(Umbraco.AssignedContentItem.GetPropertyValue<int>("mainImage"));
    
    var imageUrl = mediaItem.GetCropUrl("LargeSquare");
    

    Also check that crop alias is exactly "LargeSquare", it's camel sensitive, so it is "largeSquare" will not work

    Thanks,

    Alex

  • jonny cundall 15 posts 157 karma points
    Nov 12, 2018 @ 18:15
    jonny cundall
    0

    yes that works. but I've no idea why the other syntax, which works on my live site, does not work

Please Sign in or register to post replies

Write your reply to:

Draft