Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
File is not getting downloaded
Hi All,
i have one portlet in liferay 6.2, where we can download the table data in Excel or Text format and it's working very well.
Now we are migrating to liferay 7. We implemented the portlet in DXP.
Now if are trying to download as excel or text file is not getting download and the data is appearing on browser screen.
Code:
ServletResponseUtil.sendFile(request, response, fileName, bytes, ContentTypes.TEXT_CSV_UTF8);
ServletResponseUtil.sendFile(request, response, fileName, bytes, ContentTypes.TEXT_PLAIN_UTF8);
Please help.
i have one portlet in liferay 6.2, where we can download the table data in Excel or Text format and it's working very well.
Now we are migrating to liferay 7. We implemented the portlet in DXP.
Now if are trying to download as excel or text file is not getting download and the data is appearing on browser screen.
Code:
ServletResponseUtil.sendFile(request, response, fileName, bytes, ContentTypes.TEXT_CSV_UTF8);
ServletResponseUtil.sendFile(request, response, fileName, bytes, ContentTypes.TEXT_PLAIN_UTF8);
Please help.
There's a lot missing here...
Is this done as part of a resource request or is it part of a render request. In either case, you should only be using a ServletResponseUtil.sendFile() from a servlet, but use a PortletResponseUtil.sendFile() in the scope of a portlet request.
Is this done as part of a resource request or is it part of a render request. In either case, you should only be using a ServletResponseUtil.sendFile() from a servlet, but use a PortletResponseUtil.sendFile() in the scope of a portlet request.
Action request David.
Even i changed ActionRequest to RenderRequest result is same, file is not getting downloaded.
I tried both
PortletResponseUtil.sendFile(actionRequest, actionResponse, fileName, bytes);
ServletResponseUtil.sendFile(request, response, fileName, bytes, ContentTypes.TEXT_PLAIN_UTF8);
Thaks.
I tried both
PortletResponseUtil.sendFile(actionRequest, actionResponse, fileName, bytes);
ServletResponseUtil.sendFile(request, response, fileName, bytes, ContentTypes.TEXT_PLAIN_UTF8);
Thaks.
It should not be either an action or a render request.
These types of things are best handled as a resource request. You have a link on a page, "Download my spreadsheet", which has a resource request for the portlet. The portlet uses the PortletResponseUtil.sendFile() to serve the resource request, everything will work correctly.
The problem is that you found a broken way to serve up the spreadsheets before, one that has since been fixed. They're not going to re-break things for you just so this code will work.
Instead you have to fix your code to do it the right way, the way the portlet spec expects this kind of thing to work.
These types of things are best handled as a resource request. You have a link on a page, "Download my spreadsheet", which has a resource request for the portlet. The portlet uses the PortletResponseUtil.sendFile() to serve the resource request, everything will work correctly.
The problem is that you found a broken way to serve up the spreadsheets before, one that has since been fixed. They're not going to re-break things for you just so this code will work.
Instead you have to fix your code to do it the right way, the way the portlet spec expects this kind of thing to work.
Maybe a bit late
You must disable SPA for the link.
https://dev.liferay.com/es/develop/tutorials/-/knowledge_base/7-0/automatic-single-page-applications#disabling-spa

You must disable SPA for the link.
https://dev.liferay.com/es/develop/tutorials/-/knowledge_base/7-0/automatic-single-page-applications#disabling-spa
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™