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

Blob value to display in Visualforce Page or Download as excel

Hi there,

I am retreiving binary Excel value from webservice callout which I managed to convert to blob. It works fine if I create a document for this value like this;
        blob image = res.getBodyAsBlob();
        Document d = new Document(); = 'CustomerByLocationFile.xls';
        d.body = image;
        d.folderId = UserInfo.getUserId();
        insert d;
I want to be able to display this same file in the VisualForce page or make it download in Excel format;
I have tried using the attribute; contenttype="application/" in the page tag, which downloads the excel file but it is in not Readable format.

If someone could please help me out on displaying these properly in excel download or even in VFpage that would be of great help.

Thanks in advance!

You can try using the OutputLink by getting the Document Id. 
      <apex:outputLInk value="{!d.Id}" target="_blank">Download File</apex:outputLink>
Hi Kartik,

Sorry on the delayed response.
I might have put the question in incorrect order.

Actually my approach is: On click of the button, I am doing a REST callout, which returns me blob value. I want to display this into the VF page. The blob value I am getting in return is a binary excel file.

Would you know how to resolve this?
Hi Justin. I am stuck on the same requirement. In case you have find the solution, please share. Thanks.
Hey Sidharth,

Sorry for the late response. I did resolve this issue. What I had to do was convert the blob into attachment and displayed in that way to the users.
Let me know if I can be of any help.

Hi Justin,

Thanks for the reply. What i am doing right now is getting the blob value from api response, and providing a download link for it in a vf page. Exaplined link :

Also, alternatively i can save the blob value as an attachment in sf, but not sure how to display the excel file into vf page? Is that something possible ?