U4-6551 - GetMediaByPath returning null

Created by Richard Terris 24 Apr 2015, 08:37:51 Updated by Warren Buckley 21 Jun 2016, 08:23:58

Is required for: COU-349

MediaService.GetMediaByPath("/media/1028/img2.jpg"); is returning null We have tried with various hard coded image paths for testing but getting null - the path above is the same format as the example given in the method documentation so we now assume this to be a bug.

What did you expect to happen? We expect an IMedia object to be returned. What actually happened? null was returned.

Comments

Arnold Visser 05 Nov 2015, 15:28:30

Still around in Umbraco 7.3.1


Marc Goodson 16 Mar 2016, 11:59:08

I think this is because the GetMediaByPath method is looking for an exact match of the path of the media file in the umbracoFile field in the database, however if you are using the cropper, the exact path won't be the only thing stored in the umbracoFile property, you will have instead a JSON object containing the src of the image, but additional crop information - so the lookup fails and returns null.

Func<string, Sql> createSql = url => new Sql().Select("*") .From() .InnerJoin() .On<PropertyDataDto, PropertyTypeDto>(left => left.PropertyTypeId, right => right.Id) .Where(x => x.Alias == "umbracoFile") .Where(x => x.VarChar == url);

fix would be to either additionally store the src media url in the VarChar field (the json object is now in the nVarChar field) or update the query above in the Media Service GetMediaByPath to look for a value 'beginning with' {src: '/media/1223/mediapathfile.jpg' etc


Claus Jensen 14 Jun 2016, 15:44:32

PR: https://github.com/umbraco/Umbraco-CMS/pull/1330


Warren Buckley 21 Jun 2016, 08:23:58

All good @claus merged in


Priority: Task - Pri 1

Type: Bug

State: Fixed

Assignee:

Difficulty: Normal

Category:

Backwards Compatible: True

Fix Submitted:

Affected versions: 7.2.2, 7.4.3

Due in version: 7.5.0

Sprint: Sprint 36

Story Points:

Cycle: