Message Boards

Download File from server

Iñigo Boyano, modified 2 Years ago.

Download File from server

Junior Member Posts: 96 Join Date: 2/4/14 Recent Posts

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, 

thumbnail
Mohammed Yasin, modified 2 Years ago.

RE: Download File from server

Liferay Master Posts: 591 Join Date: 8/8/14 Recent Posts

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);
	

 

Iñigo Boyano, modified 2 Years ago.

RE: Download File from server

Junior Member Posts: 96 Join Date: 2/4/14 Recent Posts

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

thumbnail
Olaf Kock, modified 2 Years ago.

RE: RE: Download File from server

Liferay Legend Posts: 6403 Join Date: 9/23/08 Recent Posts

show your code, and tell us how it behaves. (the serveResource method probably is enough)