// download arquivo @RequestMapping(value = "/{id}/download", method = RequestMethod.GET) public void getFile(@PathVariable("id") Long id, HttpServletResponse response) { try { Documento documento = serviceDocumento.find(Documento.class, id); if (documento != null) { InputStream is = new ByteArrayInputStream(documento.getArquivo()); response.setContentType(documento.getTipo()); response.setHeader( "Content-Disposition", "attachment; filename=" + documento.getNomeOriginal().replace(" ", "_")); IOUtils.copy(is, response.getOutputStream()); response.flushBuffer(); } } catch (IOException ex) { throw new RuntimeException("IOError writing file to output stream"); } }