File is not getting downloaded

thumbnail
Liferay Dev, modified 7 Years ago. Junior Member Posts: 81 Join Date: 5/17/15 Recent Posts
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.
thumbnail
David H Nebinger, modified 7 Years ago. Liferay Legend Posts: 14933 Join Date: 9/2/06 Recent Posts
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.
thumbnail
Liferay Dev, modified 7 Years ago. Junior Member Posts: 81 Join Date: 5/17/15 Recent Posts
Action request David.
thumbnail
Liferay Dev, modified 7 Years ago. Junior Member Posts: 81 Join Date: 5/17/15 Recent Posts
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.
thumbnail
David H Nebinger, modified 7 Years ago. Liferay Legend Posts: 14933 Join Date: 9/2/06 Recent Posts
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.
thumbnail
David H Nebinger, modified 6 Years ago. Junior Member Posts: 25 Join Date: 4/9/15 Recent Posts