[SalesForce] Accessing an Image from Sites, stored in a Rich Text Area field

I have a Rich Text Area field in which I'm storing images only. When this field is accessed through APEX, an HTML tag <img> is returned with it's properties.

In the controller of my VF page, I am doing a substring to get the URL of the image from the src property which works well when I access the page from within the SF instance /apex/thePage. The result URL that I'm getting is something like this :

https://c.cs17.content.force.com/servlet/rtaImage?eid=a1Cg0000000JDAi&feoid=00Ng0000000MTcp&refid=0EMg00000007o4U

If I access the same relative path through my site however, I don't have permissions to access that record/object (See image below).

enter image description here

I've got 2 questions here:

1) Where are the images stored in the instance (which object), and can
they be accessed from anywhere else but the RTA field itself?

2) Is there any way to reference the URL of the image in a specific
format so that the Site can access it (If an object needs permissions for the site profile, which object would that be)?

NOTES :

1) I can't output the RTA field on the page due to the complexity and
the structure of the template, I can only reference the URL of the
image (Using <apex:image adds other elements around the image).

2) The data model is already built this way, so please don't suggest
moving the images to other objects etc.

Best Answer

Are you sure the rich text field is visible to the site profile? It's not included in the regular list, you have to go to the site settings and access the profile from there where you can then check whether the field level security is good. I assume it is since you have the URL , but then I don't know why you can't access the image. Have you tried using straight tags instead of using the Visualforce image tag?

We use rich text fields for our website and that displays images from the same server without problems; the image below is accessed via this URL:

http://www.spkeasey.com/servlet/rtaImage?eid=a0Fi0000000BX4l&feoid=00Ni0000000GnlW&refid=0EMi00000008S3k

CrowdGuide Logo served up from a RTA

I suspect that you might need to modify the domain part of your image URL to use that of your site, as it is the URL will be for internal access and the site user wouldn't have access to it. You can get the site base URL using: {!$Site.CustomWebAddress}, for example I get the URL of static resources on our site like so:

{!$Site.CustomWebAddress}{!$Resource.ResourceName}"
Related Topic