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
RE: RE: Download File from server
Hi,
I have a folder in the server with files that i have to can downloaded from a portlet.
I have the ajax call to call the serveResource but i dont know how to generate the download for that file in the browser.
Any help¿?
Kind regards,
Hi,
You can try fetching the byte array of the file from your server folder and then send it for download using ServletResponseUtil.
Ex.
byte[] fileBytes = FileUtil.getBytes(new File("localfilepath//sample.pdf"));
ServletResponseUtil.sendFile(PortalUtil.getHttpServletRequest(resourceRequest), PortalUtil.getHttpServletResponse(resourceResponse), "sample.pdf", fileBytes);
Hi Mohammed,
I've tried your solution before but the file is not downloaded and browser show nothing either.
I've tried also the liferay core way with a fileEntry and nothing happends also.
I'm missing something but i don't know what.
Thanks a lot
show your code, and tell us how it behaves. (the serveResource method probably is enough)
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™