Last active
October 26, 2016 15:06
-
-
Save evaldeslacasa/f8f7819224035087026473a9016a2fa0 to your computer and use it in GitHub Desktop.
Download file from Liferay custom portlet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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