ScienceProjectService service = getService(ScienceProjectService.class);
Integer id = new Integer(request.getParameter("key"));
Integer projid = new Integer(request.getParameter("projkey"));
AttachmentVo data = service.loadProjectFilesData(getAuthenticatedUser(request).getUserId(),projid,id);
String fileName = data.getName();
if(fileName == null){
return;
}
//fixing an issue I experienced when viewing files with spaces in the file name
fileName = fileName.replace(' ', '_');
//fixing cache issue in IE
response.setHeader("Pragma", "public");
response.setHeader("Cache-Control", "max-age=0");
//normal response requirements for prompting user
response.setContentType("application/download");
response.setHeader("Content-Disposition","attachment; filename="+fileName);
//
response.getOutputStream().write(data.getContents());
response.getOutputStream().flush();
response.getOutputStream().close();
}