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
Rajesh ShahRajesh Shah 

Problem with html image tag

I have a force.com site with lets say XYZ as the home page. In one of the subsequent pages I am displaying images uploaded in the attachment object of the related record. To display the image, I am forming the url as '/servlet/servlet.FileDownload?file=' + attachmentId;' This works fine when I use the apex image tag to display the images on the site.

However due to another problem, I had to use html image tag. But when I use the html tag, the images don't get displayed. In order to display them, I have to change the url as  '/XYZ/servlet/servlet.FileDownload?file=' + attachmentId;'. This works fine in sites but gives error when viewing the site page as a normal VF page when logged in. 

Can anyone explain why is difference between apex image and html image? And what are the possible solutions I have to display the images on both sites and VF page?

As of now, I am trying to solve the other problem I am facing using apex image. If that works out, I will use Apex Image tag.

Best Answer chosen by Admin (Salesforce Developers) 
BulentBulent

The best practive is not to hard code urls in your page. Use the $Action like following

 

<img src="{!URLFOR($Action.Attachment.Download, pic.id)}">

 

 this will generate the correct url both for sites and for internal use cases.

 

All Answers

BulentBulent

The best practive is not to hard code urls in your page. Use the $Action like following

 

<img src="{!URLFOR($Action.Attachment.Download, pic.id)}">

 

 this will generate the correct url both for sites and for internal use cases.

 

This was selected as the best answer
Rajesh ShahRajesh Shah
Thanks. That works
Message Edited by Rajesh Shah on 02-23-2010 11:48 AM