You need to sign in to do that
Don't have an account?
![Sidharth Sidharth](https://dfc-org-production.my.site.com/img/userprofile/default_profile_45_v2.png)
Blob value (Excel) - display/download link in VF Page
Hi,
I have a requirement to display/provide download link to the http blob response in visualforce page.
I am able to create a new attachment/document from blob value and provide a download link to that in vf page using {!URLFOR($Action.Attachment.Download,ReportName)}".
But i dont want to create a new attachemnt, just pass it from apex to vf page.
Any ideas ?
Thanks
Sid
I have a requirement to display/provide download link to the http blob response in visualforce page.
I am able to create a new attachment/document from blob value and provide a download link to that in vf page using {!URLFOR($Action.Attachment.Download,ReportName)}".
But i dont want to create a new attachemnt, just pass it from apex to vf page.
Any ideas ?
Thanks
Sid
And the link should be (xlsx file):
In case you are using a xls file:
Let e know
All Answers
In your controller create a "BASE64_ENCODED_BLOB" String getter in which you can encode the binary in Base64 (utf8).
When the user clicks on the link opens up the pdf in the tab (tested with Chrome, FF and Safari on MacOS)
Hope this helps
--
May the Force.com be with you
1. The blob value i am getting from http response, is actually a xlsx file, which i can store it as an attachment using httpResponse.getBodyasBlob().
Will the suggested pdf solution will work in case of xlsx too ?
Can you provide a code snippet of encoding the binary in Base64 (utf8) ?
Thanks again!
And the link should be (xlsx file):
In case you are using a xls file:
Let e know
Only thing is do we have control over naming the downloaded file, as it seems to be defualt to download.xlsx.
Not working in Internet Explorer.. Is there any solution for this Please.
Before: we were opening a vf page, which has a download link, click that will download the file
<a href="data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;content-disposition:attachment;base64,{!CustomCreditReport}">DOWNLOAD</a>
Now: i am cutting down the steps, and want to directly download the file on button click
window.open('data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;content-disposition:attachment;base64,customReport');
But this is downloading a empty file. I can alert customReport and it has the data.
Is this possible ? Thanks.
Sid
I have similar requirment - There are some search filters where user can select the search criteria and once he click on dowmload an xlsx file should create and dowload on user system.
In my case, we are getting a file content by calling an external partner web service, which i am encoding (EncodingUtil.base64Encode), and passing to vf page as string.
Apex:
String customCreditReport = EncodingUtil.base64Encode(httpResponse.getBodyasBlob());
(where, httpResponse is the external web service response)
VF Page:
<apex:pageBlock>
<a href="data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;content-disposition:attachment;base64,{!CustomCreditReport}">DOWNLOAD</a>
</apex:pageBlock>
-Sid
I was looking for similar solution but for PDF. i am able to display the blob as PDF in VF page with the following code.
<a href="data:application/pdf;content-disposition:attachment;base64,{!pdfString}">View File</a>
Best,
NHK
The solution is working in Chrome and Firefox but not in IE 11(displying a blank white screen). Can you please suggest how can i make it to work in IE as well?
Best,
NHK
You can use download attribute for renaming the file and download it with custom name. You can use something like: Clicking this will download file with name as 'MyCustomName.pdf'.
Hope this helps!