function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Hemant Gulati 4Hemant Gulati 4 

How to access Image saved in Rich text box field through REST API

Hello All,

I need your help on the foloowing issue:-

I have attach a image file in RICH TEXT BOX field in one of the objects. Now i am trying to aceess that image through REST API from outside salesforce. i want to show that image on my Public site (which is outside salesfoce).

Please share the code  to access the image (stored in rich text box field of an object) through REST API.

Eagerly awaing for the answers.

Thanks in advance..

Best Answer chosen by Hemant Gulati 4
Hemant Gulati 4Hemant Gulati 4
I foudn the answer here:-

All Answers

Hi Hemant,

I used the below mentioned code to extract the src of image from rich text area field. Can you please try with it?
private String formatRichText(String strRichText)
		return strRichText.subStringBetween(strRichText.contains('src') ? 'src="' : 'href="','"').replaceAll('&','&');

Simply pass the rich text field value as parameter to the function. It will return the URL of the image. Then in page you can use img tag to display the image:
<img alt="Image Not Found" src="{!strRichText}" style="height:150px;max-width:100%;"/><br/><br/>

Hemant Gulati 4Hemant Gulati 4
Hi Pankaj,

Thanks for reply.

I am not accessing RICH TEXT AREA image on VF page or on site.

I want to access it outside salesforce (eg from WCF servioces, or using Ajax).

So please let me know how can i accomplish this.

Hemant Gulati 4Hemant Gulati 4
I foudn the answer here:-
This was selected as the best answer