You need to sign in to do that
Don't have an account?
Render Blob content on the page
Hi,
My requirement is to display the blob content on the page, in fact i am making a callout to external webservice and getting a file content in Base64 string format (now we can covert it to Blob). But not able to display this content in correct format, as i tried with different things like -
1. converted Base64 in Blob and tried to display but it's displaying something "core.filemanager.FileBlobValue@bd9997c " on the page
2. Directly tried to display Base64 string then obviously it's displaying raw string (very large)
etc.
I want to display that content in original format, it can be of any type (pdf, xls, doc,rtf etc).
Any help would be appreciate.
You need a way to deliver the BLOB to the client so it can render it. Base64 would work if you used a DATA URL, but depending on the browser, content might not fit in the DATA URL limit (IE6 supports 4096 characters, for example). Without knowing the content type in advance, you would need to render the data inside an IFRAME as an additional inconvenience, as HTML doesn't just render any type of file without being told what to do with it. For example, a PDF needs an IFRAME, while an IMAGE needs a IMG tag, etc. If you limit yourself to a select list of file types, you could probably get away with conditional rendering of certain types, and provide an IFRAME for all remaining types that HTML doesn't have distinct types for. I think your functionality may be too generic to provide any solution other than "allow the user to download the file directly to their computer."
Hi,
Thanks for valuable reply.
I am getting the file content from external file server using webservice callout also getting the content type of file, now is there any way to render the content on page..?
I want to have same functionality as in salesforce we upload a file in document object and when we click on "view File" link, it render the file if file is of type text/image/pdf otherwise it gives the option to dowload/save file.
Temporarily i am doing same, just getting content from callout..., saving the file content in document object and finally redirecting user to that (View File) link. But the prob is that we dont want to save file in salesforce.
As your reply, can we implement this using IFRAME ? if so then in which format(Base64/Blob/String..) we need to pass the file content in IFRAME. A sample example will help me more if you could..
You'll have to set the Content-Type to "application/octet-stream", and then you'll be at the mercy of the browser to determine the type of file and how to display it. I've never tried this before personally, but I think it should work on most browsers without a problem. However, you may have to implement this as a REST method in order to set the correct headers.
This knowledge article might help you,
http://help.salesforce.com/apex/HTViewSolution?id=000005941&language=en_US
How can I Display Base64 Data on a Visual force page?
<apex:page controller="ViewImage" cache="true">
<img src="data:{!att.ContentType};base64,{!image}" /> </apex:page>
public class ViewImage {
public Attachment att {
get {
if (att == null) {
String id = ApexPages.currentPage().getParameters().get('AttachmentID');
att = [SELECT Body, ContentType, Name FROM Attachment WHERE ID = :id];
}
return att;
}
private set;
}
public String image {
get {
return EncodingUtil.Base64Encode(att.body);
}
}
}
Hello Alok,
Have you find any alternative for this requirement? If Any please suggest me..
I am currently stuck at the same issue. Have you been able to resolve yours. Please suggest me the same?
Hope this helps
Kindly share if you find any solution for the issue posted? Same issue I'm also facing.
Appreciate any solutions!
Regards
Sarah