2

I need to display attachments on a visual force page for the Case object.

This is the code I am using. I had it working for awhile, but it somehow broke down. It gets all the attachments, but it will not show the images.

<apex:repeat value="{!Case.attachments}" var="att">
            <apex:panelgrid columns="1">
                <h1>Image/h1>
                <apex:image url="/servlet/servlet.FileDownload?file={!att.Id}"/>
            </apex:panelgrid>
</apex:repeat>

3 Answers 3

3

Try using this :

<apex:repeat value="{!Case.attachments}" var="att">
    <apex:panelgrid columns="1">
        <h1>Image</h1>
        <apex:image url="{!URLFOR($Action.Attachment.Download, att.id)}"/>
    </apex:panelgrid>
</apex:repeat>

Let me know if it works for you. Thanks

0
2
        <apex:repeat value="{!Case.Attachments}" var="att">
            <apex:panelgrid>
                <apex:image styleClass="vitality-check-img" url="{!URLFOR($Action.Attachment.Download, att)}" rendered="true"/>
            </apex:panelgrid>
        </apex:repeat>
1

Looks like you want to display the files so the users can download them. Instead of using apex:image, do this:

<apex:outputLink value="/{!att.Id}" target="_blank">View File</apex:outputLink>

This ensures to display all kinds of file, be it pdf or jpeg or text. Let me know if it works for you.

2
  • No, the attachments need to be viewed on the page, not download links. Otherwise it would be practical to just add the attachment related list to the page @heisenberg Commented Jun 4, 2015 at 18:23
  • I think you should remove this "/servlet/servlet.FileDownload?file=" and pass the att Id only. Have you tried this? - <apex:image value="/{!att.Id}"/> Commented Jun 4, 2015 at 18:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .