Skip to content

Instantly share code, notes, and snippets.

@dampee
Last active March 2, 2020 18:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dampee/c2f47400b2aea969a42c to your computer and use it in GitHub Desktop.
Save dampee/c2f47400b2aea969a42c to your computer and use it in GitHub Desktop.
Resave all images. After an umbraco Upgrade from 6 to 7 you might have empty .URL's when using the image cropper. Resave all images by calling this API endpoint once.
using System.Web.Http;
using System.Collections.Generic;
using Umbraco.Core.Models;
using Umbraco.Web.WebApi;
namespace Our.Umbraco
{
public class UpgradeHelperController : UmbracoAuthorizedApiController
{
[HttpGet()]
public string ResaveAllImages()
{
var mediaService = Services.MediaService;
var rootmedia = mediaService.GetRootMedia();
foreach (var media in rootmedia)
{
mediaService.Save(media);
foreach (var item in media.Descendants())
{
mediaService.Save(item);
}
}
return "All media items saved";
}
}
}
@calvindavis
Copy link

Really useful, thanks!

I had to rewrite for Umbraco 8: https://gist.github.com/calvindavis/3b6d2572041a62e69179c827557578e0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment