You need to sign in to do that
Don't have an account?
shabuthomas
Displaying Notes & Attachments on Visual Force Pages
Would you please help me to display Notes & Attachments on a Visual Force page having CUSTOM controller ?
Is there any tag for it ?
Is there any tag for it ?
Thanks Ron. It ended up being much simpler than I thought:
<img src="/servlet/servlet.FileDownload?file=00P80000003PXMyEAO
All Answers
obj.id is the object you want to see the related list for.
You might be able to do it with a data URL:
You would just embed the mime type and base64 encoded content of the attachment.
The only problem is that while Firefox and others support data URLs, IE does not (at least right now).
Thanks Ron. It ended up being much simpler than I thought:
<img src="/servlet/servlet.FileDownload?file=00P80000003PXMyEAO
That works inside Salesforce, but apparently not on a public Sites VF page. The data url has worked for me, but again IE doesn't support data urls and the next version IE 8.0 will only support data urls up to 32KB in length.
I'm curious, has anyone been able to push a word/excel/pdf (non-public images) to a public Sites page?
I've tried setting the <apex:page ...> attribute to a specific mime type, but getting the attachment body (base64 content) into the page hasn't been as easy as I thought it would be.
I'm having a similar issue. I have a "ViewImage" VF page and I obviously want it to render as an image. While I'm close, it looks like Apex/VF isn't handling upper ASCII strings correctly. Here's my code:
VF Page
======================
<apex:page showHeader="false" sidebar="false" controller="ViewImageCtrl" contentType="image/gif">{!data}</apex:page>
Controller
======================
public class ViewImageCtrl {
public String data {get;set;}
public ViewImageCtrl(){
//the string below is base 64 encoded version of the image availabe at /s.gif
data = EncodingUtil.base64Decode('R0lGODlhAQABAID/AMDAwAAAACH5' + 'BAEAAAAALAAAAAABAAEAAAICRAEAOw==').toString();
}
}
The real image has the following byte sequence:
4749 4638 3961 0100 0100 80FF 00C0 C0C0 0000 0021 F904 0100 0000 002C 0000 0000
0100 0100 0002 0244 0100 3B
The image rendered by my VF page has the following incorrect byte sequence (NOTE they are similar but this version is longer):
4749 4638 3961 0100 0100 EFBF BDEF BFBD 00EF BFBD EFBF BDEF BFBD 0000 0021 EFBF
BD04 0100 0000 002C 0000 0000 0100 0100 0002 0244 0100 3B
The first diff is the 11th byte sequence - the real version has 80 which is in the upper ASCII range of bytes. Its my hunch that Apex is escaping this byte because it doesn't recognize it.
Thoughts? Workarounds?
Note to SF Prod Mgmt: VF pages need to be able to more easily return binary streams of data. Ideally you should have some sort of "new" root tag (maybe <apex:binary> or <apex:file>) which makes this sort of functionality explicit with a tag that accepts only Blob fields.
-Richard Vanhook
After looking at the byte sequences a little more, its pretty obvious that any byte > 127 gets escaped to three bytes EF BF BD. For example, the sequences stacked on top of each other starting at 11th byte:
11 12 13 14 15 16 17
80 FF 00 C0 C0 C0 0000
EFBFBD EFBFBD 00 EFBFBD EFBFBD EFBFBD 0000
This is just a stab in the dark, but would <apex:outputText escape="false" .... work?
Ron
Cliff McQuirter gave me the following solution to dynamically rendering attachments in Sites (thanks Cliff!):
============================
Page:
============================
<apex:page standardController="Account" extensions="InputFileControllerExtension">
<apex:messages />
<apex:form id="theForm">
<apex:pageBlock >
<apex:pageBlockSection >
<apex:inputFile value="{!attachment.body}" filename="{!attachment.name}"/>
<apex:commandButton value="Save" action="{!save}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
<apex:pageBlock >
<apex:repeat value="{!account.attachments}" var="attachment">
<apex:image height="200px" value="{!URLFOR($Action.Attachment.Download, attachment.Id)}"/><p/>
</apex:repeat>
</apex:pageBlock>
</apex:page>
============================
Controller
============================
public class InputFileControllerExtension {
ApexPages.StandardController stdController;
private final Account acct;
public Attachment attachment {
get {
if (attachment == null) attachment = new Attachment();
return attachment;
}
set;
}
public InputFileControllerExtension(ApexPages.StandardController stdController)
{
this.acct = (Account)stdController.getRecord();
this.stdController = stdController;
}
public PageReference save() {
attachment.parentid = acct.id;
insert attachment;
PageReference page = ApexPages.currentPage();
page.setRedirect(true);
return page;
}
}
============================
Config Steps:
============================
a. Go to App Setup > Develop > Sites > [your site] > Public Access Settings
b. Scroll down to Standard Object Permissions. Check to see whether your object has read permission (by default, only Ideas has Read checked).
c. Edit - add Read permission to your object
Here's another example of dynamically displaying image attachments. I hope this helps.
//Controller:
public List<Attachment> postImgId;
String qp;
public SampleController()
{
qp = ApexPages.currentPage().getParameters().get('id');
postImgId = [Select Id From Attachment where ContentId = :qp limit 1];
}
public string getPostImgId()
{
String strImgLink = '/servlet/servlet.FileDownload?file=' + postImgId[0].Id;
return strImgLink;
}
<!--VF markup: -->
<apex:image value="{!PostImgId}" />
please provide the complete code to display the attached files in VF Page
Please help me getting this error
Error: Missing required attribute list in <apex:relatedList> in
http://www.salesforce.com/us/developer/docs/pages/index.htm