Crick3t
Crick3t

Reputation: 1151

Image src is not filled out in Umbraco content

We have a document type with Richtext editors and putting images in the text. When we look at the content under Umbraco the image is displayed and seems fine.

When Umbraco saves the content and omits the src part, I guess to make sure it always has the right domain name when the content is displayed on different servers/website/domains... So it is not goind to be in the dabase or in the indexes.

The issue is, when we get the content by the ContentService or Examine the image link is not there, it only has the data-udi:

<img style="width: 479px; height: 288px;" src="?width=479&amp;height=288&amp;mode=max" alt="" data-udi="umb://media/0fc389ff96e949169014c0faf05220d0" />

instead of this, like under Umbraco:

<img style="width: 479px; height: 288px;" src="https://www.example.com/media/5gengd5j/image1.png?width=479&amp;height=288&amp;mode=max" alt="" data-udi="umb://media/0fc389ff96e949169014c0faf05220d0" />

What should we do to make sure the image links are generated, like they are done under the back office?

Is there a method we could call with the whole content that would fill in the src field based on the GuidUdi?

IContentService cs = Services.ContentService;
IContent content = cs.GetById(ID);
string mainString = content.Properties["main"].GetValue()
???

(We are using Umbraco 8.2.1)

Upvotes: 0

Views: 249

Answers (1)

Crick3t
Crick3t

Reputation: 1151

After digging around in Umbraco's source code I have found the solution here.

The TemplateUtilities has methods to insert the links to various objects based on the data-udi:

string mainString = content.Properties["main"].GetValue()
mainString = TemplateUtilities.ParseInternalLinks(mainString, Current.UmbracoContext.UrlProvider);
mainString = TemplateUtilities.ResolveUrlsFromTextString(mainString);
mainString = TemplateUtilities.ResolveMediaFromTextString(mainString);

Upvotes: 1

Related Questions