Image URL replacement

Posted by Community Admin on 04-Aug-2018 19:36

Image URL replacement

All Replies

Posted by Community Admin on 29-Apr-2014 00:00

I am trying to expose some content for a NewsItem for an external application.  I would like to return all the content of a news item.  I can retrieve the content easy enough, however images look something like this:  <img src="[images|OpenAccessDataProvider]80373ee1-f441-6e81-b252-ff0000757d21" />

Is there a quick API where I can pass it a content string and get the content back with the actual URLs replaced?

I have an approach so far but it would be nice if there was something easier (or perhaps more efficient).  Currently I do something like this:

1.  Retrieve the NewsItems using App.WorkWith().NewsItems().Published().Get()

2.  Search through NewItem.Content looking for <img src="[images|OpenAccessDataProvider]...

3.  Get the GUID in the SRC attribute.

4.  Use the LibraryManager to get the image URL:

LibrariesManager librariesManager = LibrariesManager.GetManager();
Image image = librariesManager.GetImages().Where(i => i.Id == id).FirstOrDefault();
var url = image.MediaUrl;

5.   Replace the image src with the URL from the .MediaURL.

Are there any shortcuts to this or any other helper APIs in the SDK?

 

Posted by Community Admin on 02-May-2014 00:00

Hello Gary,

This is the correct approach. The image url in the content of the news Item could be get by parsing the image id and than get the Item and the properties you need.

Regards,
Svetoslav Manchev
Telerik

 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

This thread is closed