@RequestMapping(value = "/getfile") public String dovnloadFile(@RequestParam("id") Integer fileId, HttpServletResponse response) { File file = null; try { file = fileService.getFile(fileId); } catch (HibernateException e) { } if (file != null) { if ((getCurrentUser().equals(file.getRecord().getUser())) || file.getRecord().getAccess().getId() == 2) { response.setContentType(file.getType()); response.setContentLength(file.getFile().length); response.setHeader( "Content-Disposition", "attachment; filename=\"" + file.getFilename() + "\""); try { FileCopyUtils.copy(file.getFile(), response.getOutputStream()); } catch (IOException e) { e.printStackTrace(); } } } return null; }