Copied to clipboard

Flag this post as spam?

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


  • Sebastian Dammark 583 posts 1407 karma points
    Feb 07, 2024 @ 13:53
    Sebastian Dammark
    0

    Media cache not found

    I've had an accident on a website, running Umbraco 12.0.1 and I had to restore some files from the hosting backup.

    System.IO.FileNotFoundException: Could not find file 'd:\web\localuser\username\public_html\umbraco\Data\TEMP\MediaCache\6\c\1\c\5\a\5\b\5e5e.png'.
    

    Now that everything is back in it's place, I have a problem with cached media that doesn't exists.

    How do I create new cached files ?

    Cached file that doesn't exists: https://hedenstedfotoklub.dk/media/werpjeka/21-06-kgs.jpg?rxy=0.37743107346478094,0.2944656811154796&width=570&height=285&v=1d965c4e161f8f0

    Actual file that works fine: https://hedenstedfotoklub.dk/media/werpjeka/21-06-kgs.jpg

  • Marc Goodson 2157 posts 14434 karma points MVP 9x c-trib
    Feb 08, 2024 @ 09:10
    Marc Goodson
    0

    Hi Sebastian

    The MediaCache folder consists of copies of images after the have been processed by ImageSharp...

    So if an image is request on the site directly to the image eg

    https://hedenstedfotoklub.dk/media/werpjeka/21-06-kgs.jpg

    this doesn't use the MediaCache, and will not create anything in the cache

    but if you add resize instructions

    https://hedenstedfotoklub.dk/media/werpjeka/21-06-kgs.jpg?width=570&height=285

    You'll see the image is being resized, and a new file is added somewhere in the MediaCache folder (difficult to see as the files are hashed)

    Next time a request comes in for that image with those specific querystrings, the url will be hashed, and the cache version retrieved from the media cache...

    ... so in your circumstance, it isn't so much 'how do I restore the mediacache' that is the issue, it is more, why isn't my image being resized...

    eg

    the version that contains the 'v=' fails

    https://hedenstedfotoklub.dk/media/werpjeka/21-06-kgs.jpg?rxy=0.37743107346478094,0.2944656811154796&width=570&height=285&v=1d965c4e161f8f0

    it failed without the v parameter too

    https://hedenstedfotoklub.dk/media/werpjeka/21-06-kgs.jpg?rxy=0.37743107346478094,0.2944656811154796&width=570&height=285

    but we saw just the width and height on it's own worked correctly, if I adjust the rxy point to round up the decimals

    https://hedenstedfotoklub.dk/media/werpjeka/21-06-kgs.jpg?rxy=0.4,0.3&width=570&height=285

    it is also fine, so is it something to do with the length of the decimals???

    hoping that helps!

    regards

    Marc

  • Sebastian Dammark 583 posts 1407 karma points
    Feb 08, 2024 @ 09:36
    Sebastian Dammark
    0

    That's odd, because I just generate the image url like this:

    var images = content.Value<IEnumerable<IPublishedContent>>("images");
    
    foreach(Image image in images) {
        var width = (int)image.Value("umbracoWidth");
        var height = (int)image.Value("umbracoHeight");
        var format = (width > height) ? "Landskab" : "Portræt";
    
        <img src="@Url.GetCropUrl(image, format)" loading="lazy" />
    }
    

    The example above is slightly simplified :)

  • Marc Goodson 2157 posts 14434 karma points MVP 9x c-trib
    Feb 08, 2024 @ 14:08
    Marc Goodson
    0

    Yes, so why is

    Url.GetCropUrl generating a Url that isn't being processed!

    What happens if you upload the image afresh as a new media item and pick in here... ?

  • Sebastian Dammark 583 posts 1407 karma points
    Feb 08, 2024 @ 22:38
    Sebastian Dammark
    0

    If I remove the original, and re-upload it, the cache is rebuild and everything looks fine.

    But I hope there is a way to rebuild the cached media files, other than upload them one by one.

  • Marc Goodson 2157 posts 14434 karma points MVP 9x c-trib
    Feb 08, 2024 @ 22:51
    Marc Goodson
    100

    Hi Sebastian

    So that shows there isn't an issue with the image itself and the getcropurl instruction...

    And if you vary any single character in the Url it seems to work...

    so I think the issue is the hash of those exact parameters is matching something in your media cache that is corrupted...

    So I think if you delete the contents of the media cache folder, that should remove the corruption on this file...

    But will cause all images on the site to need to be processed again, and the media cache folder will build back up overtime

    Regards

    Marc

  • Sebastian Dammark 583 posts 1407 karma points
    Feb 10, 2024 @ 15:29
    Sebastian Dammark
    0

    Thanks Marc,

    I just renamed the MediaCache folder to something else. That forced Umbraco to generate new cached files.

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

Please Sign in or register to post replies