diff --git a/src/Umbraco.Core/Services/IMediaService.cs b/src/Umbraco.Core/Services/IMediaService.cs
index 91e8e6fc84..e6a7b34138 100644
--- a/src/Umbraco.Core/Services/IMediaService.cs
+++ b/src/Umbraco.Core/Services/IMediaService.cs
@@ -179,10 +179,10 @@ namespace Umbraco.Core.Services
void DeleteVersion(int id, Guid versionId, bool deletePriorVersions, int userId = 0);
///
- /// Gets an object from the url of the 'umbracoFile' property.
+ /// Gets an object from the path stored in the 'umbracoFile' property.
///
- /// Url of the media item to retreive
+ /// Path of the media item to retreive (for example: /media/1024/koala_403x328.jpg)
///
- IMedia GetMediaByUrl(string mediaUrl);
+ IMedia GetMediaByPath(string mediaPath);
}
}
\ No newline at end of file
diff --git a/src/Umbraco.Core/Services/MediaService.cs b/src/Umbraco.Core/Services/MediaService.cs
index c2d82a6556..882261db58 100644
--- a/src/Umbraco.Core/Services/MediaService.cs
+++ b/src/Umbraco.Core/Services/MediaService.cs
@@ -295,20 +295,22 @@ namespace Umbraco.Core.Services
}
///
- /// Gets an object from the url of the 'umbracoFile' property.
+ /// Gets an object from the path stored in the 'umbracoFile' property.
///
- /// Url of the media item to retreive
+ /// Path of the media item to retreive (for example: /media/1024/koala_403x328.jpg)
///
- public IMedia GetMediaByUrl(string mediaUrl)
+ public IMedia GetMediaByPath(string mediaPath)
{
- var umbracoFileValue = mediaUrl;
- var isReszed = mediaUrl.Contains("_") && mediaUrl.Contains("x");
- //If the image has been resized we strip the "_403x328" of the original "/media/1024/koala_403x328.jpg" url
- if (isReszed)
+ var umbracoFileValue = mediaPath;
+ var isResized = mediaPath.Contains("_") && mediaPath.Contains("x");
+ // If the image has been resized we strip the last part of the original "/media/1024/koala_403x328.jpg" url.
+ // We're can then find propertydata containing the left part.
+ if (isResized)
{
- var underscoreIndex = mediaUrl.LastIndexOf('_');
- var dotIndex = mediaUrl.LastIndexOf('.');
- umbracoFileValue = string.Concat(mediaUrl.Substring(0, underscoreIndex), mediaUrl.Substring(dotIndex));
+
+ var underscoreIndex = mediaPath.LastIndexOf('_');
+ var dotIndex = mediaPath.LastIndexOf('.');
+ umbracoFileValue = string.Concat(mediaPath.Substring(0, underscoreIndex), mediaPath.Substring(dotIndex));
}
var sql = new Sql()
@@ -317,15 +319,12 @@ namespace Umbraco.Core.Services
.InnerJoin()
.On(left => left.PropertyTypeId, right => right.Id)
.Where(x => x.Alias == "umbracoFile")
- .Where(x => x.Text == umbracoFileValue);
+ .Where(x => x.VarChar == umbracoFileValue);
using (var uow = _uowProvider.GetUnitOfWork())
{
var propertyDataDto = uow.Database.Fetch(sql).FirstOrDefault();
- if (propertyDataDto == null)
- return null;
-
- return GetById(propertyDataDto.NodeId);
+ return propertyDataDto == null ? null : GetById(propertyDataDto.NodeId);
}
}
diff --git a/src/umbraco.editorControls/tinyMCE3/webcontrol/TinyMCEWebControl.cs b/src/umbraco.editorControls/tinyMCE3/webcontrol/TinyMCEWebControl.cs
index c2430dc027..25ba1d1b3d 100644
--- a/src/umbraco.editorControls/tinyMCE3/webcontrol/TinyMCEWebControl.cs
+++ b/src/umbraco.editorControls/tinyMCE3/webcontrol/TinyMCEWebControl.cs
@@ -325,21 +325,8 @@ namespace umbraco.editorControls.tinyMCE3.webcontrol
orgSrc = IOHelper.ResolveUrl(orgSrc.Replace("%20", " "));
- IMedia imageMedia = null;
-
- try
- {
- var pathStart = orgSrc.Contains("_") ? orgSrc.Substring(0, orgSrc.LastIndexOf("_", StringComparison.Ordinal)) + "%" : orgSrc;
-
- var mediaId = BusinessLogic.Application.SqlHelper.ExecuteScalar(string.Format("SELECT contentNodeId FROM cmsPropertyData WHERE dataNvarchar LIKE '{0}'", pathStart));
-
- var mediaService = ApplicationContext.Current.Services.MediaService;
- imageMedia = mediaService.GetById(mediaId);
- }
- catch (Exception ex)
- {
- LogHelper.Error("Error getting media item", ex);
- }
+ var mediaService = ApplicationContext.Current.Services.MediaService;
+ var imageMedia = mediaService.GetMediaByPath(orgSrc);
if (imageMedia == null)
{