Skip to content

Instantly share code, notes, and snippets.

@evaldeslacasa
Last active October 26, 2016 15:06
Show Gist options
  • Save evaldeslacasa/f8f7819224035087026473a9016a2fa0 to your computer and use it in GitHub Desktop.
Save evaldeslacasa/f8f7819224035087026473a9016a2fa0 to your computer and use it in GitHub Desktop.
Download file from Liferay custom portlet
private void downloadFile(ResourceRequest resourceRequest, ResourceResponse resourceResponse, String siteName) {
try {
File file = new File("${filePath}");
InputStream in = new FileInputStream(file);
HttpServletResponse httpRes = PortalUtil.getHttpServletResponse(resourceResponse);
HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(resourceRequest);
ServletResponseUtil.sendFile(httpReq, httpRes, file.getName(), in, "application/download");
in.close();
FileUtil.delete(file);
} catch (IOException e) {
e.printStackTrace();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment