Last active
March 2, 2020 18:34
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Really useful, thanks!
I had to rewrite for Umbraco 8: https://gist.github.com/calvindavis/3b6d2572041a62e69179c827557578e0