You need to sign in to do that
Don't have an account?

Display an image stored in Document in a Visualforce page
I'm trying to display an image that is stored as a Document. Starting with the most basic example, I am using the following:
passing the ID of the document in through the URL. It's Name displays OK, but the image does not, just showing as a 'dummy' 100x100 blank square. What syntax do I need to use? Or do I need a different approach some how?
Note, I do not want to use a Static Resource.
Thanks
<apex:page standardcontroller="Document"> <apex:outputField value="{!Document.name}"/> <apex:image id="theImage" value="!Document.Logo.jpg" width="100" height="100"/> </apex:page>
passing the ID of the document in through the URL. It's Name displays OK, but the image does not, just showing as a 'dummy' 100x100 blank square. What syntax do I need to use? Or do I need a different approach some how?
Note, I do not want to use a Static Resource.
Thanks
All Answers
However, in my test, your code displays the same 'dummy' blank square. I've also tried adding a '!' before 'Document.Id', but I get the following compilation error:
Error: Incorrect parameter type for function 'not()'. Expected Boolean, received Text
Note, I can at least get the image to display by substituting the actual ID as follows:
but this is not what I want as the image displayed needs to be derived dynamically.
Any idea what I am doing wrong?
Try adding following markup in your page Then copy the printed address from the page by above markup, and form complete URL by prepending your Salesforce instance url (It should look something like this "https://ap1.force.com/servlet/servlet.FileDownload?file=0159000000CMdyq ); And then check in the other tab that it loads expected image or not.
This is one way of debugging your issue, perhaps you may have better ways.
You original solution how works! Can only assume that I must have refreshed the page and so lost the ID from the URL. Apologies for that and thanks for your help.
<apex:outputField value="{!Document.name}"/>
<apex:image id="theImage" value="{!'/servlet/servlet.FileDownload?file=' & Document.Id}" width="100" height="100"/>
</apex:page>
I've been trying to get the above visualforce page to load on a layout for a custom object. I've been getting the following error though:
This is controller for the VF page vfDocumentImageCheck. It will query for document
whose name is LookupSymbol so that this image can be shown on the VF page. Browse
for VF page as :- https://c.ap5.visual.force.com/apex/vfDocumentImageCheck
Upload document first in the Documents folder whose name is LookupSymbol from
All Tabs - Documents - New Document
*/
public class DocumentImageCheck
{
public String imageURL{get;set;}
public DocumentImageCheck()
{
imageURL = '/servlet/servlet.FileDownload?file=';
List<document> documentList = [select name from document where
Name = 'LookupSymbol'];
if(documentList != null && documentList.size() > 0)
{
imageURL = imageURL + documentList[0].id;
System.debug(LoggingLevel.INFO, '//// imageURL modified now ' + imageURL);
}
}
}
The VF page :- vfDocumentImageCheck :-
<apex:page controller="DocumentImageCheck">
<apex:image id="image1" url="{!imageURL}" alt="Lookup" title="Lookup Symbol"/>
</apex:page>