0
votes

I'm using Umbraco with Lucene and Examine

I'm trying to get the url of a image but at the moment I get the following "umb://media/57ad107794724d0289b4f9fe44c298a8"

How can I get the URL for the media from the UDI, my code attempt so far is below.

foreach (var item in searchResults)
            {


                var content = Umbraco.Content(item.Fields["id"]);

                if (item.Fields.Keys.Contains("image"))
                {
                    var image = item.Fields["image"].Split(new[] {","}, StringSplitOptions.RemoveEmptyEntries);

                    var pathToImage = string.Join(",", image);
                    var mediaItem = Umbraco.TypedContent(pathToImage);
                    var test3 = mediaItem.Url; <--------------------Throws NullReferenceException

                }
}

Any help appreciated

1

1 Answers

0
votes

Try the following

if (item.Fields.Keys.Contains("image"))
                {
                    var imgUdi          = item.Fields["image"];
                    var udi             = Udi.Parse(imgUdi);
                    var mediaTest       = Umbraco.TypedMedia(udi);
                    string pathToImage  = mediaTest.Url;
                }

Notice how I'm using Udi.Parse to get the ID, then you can use that to get the url