Copied to clipboard

Flag this post as spam?

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

  • Mike Ryan 10 posts 91 karma points
    Jul 18, 2017 @ 15:42
    Mike Ryan

    Media Service Save method not updating with new Image Cropper sizes

    Using Umbraco.ImageCropper in version 7.2.2, I have added several new crop sizes. In order for the images in my media folders to update and reflect the new crop sizes, they need to be re-saved. Instead of manually saving potentially hundreds of images, I have programmatically used Media Service to do this. Problem is, it doesn't seem to be resetting the crops on the pictures.

    Here I set the Media Service and Umbraco Helper:

    var ms = ApplicationContext.Current.Services.MediaService;
    UmbracoHelper umbracoHelper = new UmbracoHelper(UmbracoContext.Current);

    After several foreach loops, I get the IPublishedContent version of the media node, check that it's a visible image on the slideshow, and then save it. I added the Debug.WriteLine to verify the code is being hit. I can see in the Output window that all the images have been saved, supposedly.

    foreach (var image in experience.Children()){
        IPublishedContent dynamicImage = umbracoHelper.TypedMedia(image.Id);
        if (dynamicImage.DocumentTypeAlias == "Image")
            bool isVisible = (bool)dynamicImage.GetPropertyValue("interiorSlideshow", false);
            if (isVisible)
                System.Diagnostics.Debug.WriteLine("saved " + image.Id.ToString() + ": " + image.Name);

    Output Window

    I can see the Id's of the Media nodes that were saved, but when I try to retrieve the new crop sizes:

    string mobileImg = Model.GetCropUrl(cropAlias: "iPhone");
    string tabletImg = Model.GetCropUrl(cropAlias: "iPad");
    string desktopImg = Model.GetCropUrl(cropAlias: "Desktop");

    they come back null until I manually save them in the CMS.

    I am not able to F11 into the Save method to see what is happening, any help is appreciated.


  • Paul Dermody 31 posts 110 karma points
    Aug 20, 2017 @ 20:04
    Paul Dermody

    I am having an issue that may be related to yours.

    I am changing the umbracoFile property for media items in code. You are doing the same, since that's the property that changes when you update the crops.

    The changes are saved to the database but the front-end indexes are not updated. On checking closer, it seems that the umbracoCacheInstruction table is not being updated to indicate a change to the media item and therefore the front end indexes do not get updated.

    I was thinking it's because changes to that property do not trigger a cache update, but it also doesn't update when I change other properties in the same operation.

Please Sign in or register to post replies

Write your reply to: