Foren

Portlet Liferay 6.2 + JSF - download file, filename doesn't work

Manuel Raf, geändert vor 8 Jahren.

Portlet Liferay 6.2 + JSF - download file, filename doesn't work

New Member Beiträge: 3 Beitrittsdatum: 03.02.16 Neueste Beiträge
I set filename "examplefilename.docx" in the HttpServletResponse header but when I download it has not this filename but it has potlet's name;

post my code:

FileInputStream fis = new FileInputStream(fileDocumento);
PortletResponse portletResponse=(PortletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
HttpServletResponse res = PortalUtil.getHttpServletResponse(portletResponse);

res.setHeader("Content-Disposition", "attachment; filename=examplefilename.docx");
res.setHeader("Content-Transfer-Encoding", "binary");
res.setContentType("application/octet-stream");
res.flushBuffer();

OutputStream out=res.getOutputStream();
out.write(IOUtils.toByteArray(fis));
out.close();

fis.close();
thumbnail
Olaf Kock, geändert vor 8 Jahren.

RE: Portlet Liferay 6.2 + JSF - download file, filename doesn't work

Liferay Legend Beiträge: 6403 Beitrittsdatum: 23.09.08 Neueste Beiträge
Manuel Raf:
I set filename "examplefilename.docx" in the HttpServletResponse header but when I download it has not this filename but it has potlet's name;


This looks a lot like this stackoverflow post. What in the comments discussion or in the answer there didn't help you so far? We could save some duplicate work this way. Alternatively, we could post the same answers and questions as you see on stackoverflow here as well. What do you prefer?
Manuel Raf, geändert vor 8 Jahren.

RE: Portlet Liferay 6.2 + JSF - download file, filename doesn't work

New Member Beiträge: 3 Beitrittsdatum: 03.02.16 Neueste Beiträge
there isn't solution in that post, that method works but when I download the file it is invalid or damaged, has somebody any ideas for this problem??
thumbnail
Olaf Kock, geändert vor 8 Jahren.

RE: Portlet Liferay 6.2 + JSF - download file, filename doesn't work

Liferay Legend Beiträge: 6403 Beitrittsdatum: 23.09.08 Neueste Beiträge
You could, for example, answer the comments that I've posted twice on stackoverflow: Is this in the render- or resource-phase of your portlet?

Also, please read this question and some answers to it.
Manuel Raf, geändert vor 8 Jahren.

RE: Portlet Liferay 6.2 + JSF - download file, filename doesn't work

New Member Beiträge: 3 Beitrittsdatum: 03.02.16 Neueste Beiträge
render phase...

another information: in Liferay 6.1this method worked, after I upgrade at Liferay 6.2 it has not worked
thumbnail
Neil Griffin, geändert vor 8 Jahren.

RE: Portlet Liferay 6.2 + JSF - download file, filename doesn't work

Liferay Legend Beiträge: 2655 Beitrittsdatum: 27.07.05 Neueste Beiträge
Hi Manuel,

Downloading a file in a JSF portlet should be done with a JSF ResourceHandler. Please refer to the jsf2-export-pdf-portlet for an example.

Note that in order to change the name of the downloaded file, you may need to add "Content-Disposition" to getResponseHeaders(). For more information, see FACES-2601.

Kind Regards,

Neil