From debbf87a047ee89902b8e938ddfdacf61d86714e Mon Sep 17 00:00:00 2001 From: Kenn Jacobsen Date: Mon, 31 Dec 2018 12:50:27 +0100 Subject: [PATCH] Support image crop data set when overwriting files using the API --- src/Umbraco.Core/IO/MediaFileSystem.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Core/IO/MediaFileSystem.cs b/src/Umbraco.Core/IO/MediaFileSystem.cs index 37fcdeba70..39cd7ba7ad 100644 --- a/src/Umbraco.Core/IO/MediaFileSystem.cs +++ b/src/Umbraco.Core/IO/MediaFileSystem.cs @@ -1,4 +1,6 @@ -using System; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using System; using System.Collections.Generic; using System.Drawing; using System.Drawing.Drawing2D; @@ -293,6 +295,12 @@ namespace Umbraco.Core.IO { var property = GetProperty(content, propertyTypeAlias); var svalue = property.Value as string; + if (svalue != null && svalue.DetectIsJson()) + { + // the property value is a JSON serialized image crop data set - grab the "src" property as the file source + var jObject = JsonConvert.DeserializeObject(svalue); + svalue = jObject != null ? jObject.GetValueAsString("src") : svalue; + } var oldpath = svalue == null ? null : GetRelativePath(svalue); var filepath = StoreFile(content, property.PropertyType, filename, filestream, oldpath); property.Value = GetUrl(filepath);