Copied to clipboard

Flag this post as spam?

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


  • Craig 34 posts 270 karma points
    Dec 05, 2018 @ 18:40
    Craig
    0

    ContentService SaveAndPublish Not Updating Cache for Media Picker Items?

    Hi,

    I've got a scenario where I can upload an image from the front end website which then gets allocated to a piece of content as below:

    IContent clubPage = ApplicationContext.Services.ContentService.GetPublishedVersion(club.Id);
    clubPage.SetValue("clubLogo", image.Id);
    ApplicationContext.Services.ContentService.SaveAndPublishWithStatus(clubPage);
    

    If I view the page in the Umbraco back office I can see that the media item has been allocated to it however if I then attempt to view the page on the website that uses that media item I get a

    String "nnnn" is not a valid udi

    exception thrown when attempting to work with the page's model property e.g.

    string logoUrl = clubHomePage.ClubLogo.Url;
    

    If I go back into the Umbraco Back Office and physically Save and Publish the page everything works fine but I can't rely on that as users of the site don't have access to the back office.

    Advice very much appreciated.

  • Craig 34 posts 270 karma points
    Dec 05, 2018 @ 19:14
    Craig
    100

    Okay I've found out what I need to do to get this to work. I've had to change the code to:

    IContent clubPage = ApplicationContext.Services.ContentService.GetPublishedVersion(club.Id);
    var udi = Udi.Create(Constants.UdiEntityType.Media, image.Key);
    clubPage.SetValue("clubLogo", udi.ToString());
    ApplicationContext.Services.ContentService.SaveAndPublishWithStatus(clubPage);
    

    Why? Well in v7.6.0 UDIs were introduced along with a whole bunch of "2" suffixed pickers and it appears as though the UDI needs to be used over the old Id when working with pickers.

Please Sign in or register to post replies

Write your reply to:

Draft