@RequestMapping("/download/{id}")
public ResponseEntity<byte[]> download(@PathVariable("id") Integer id) throws IOException {
EmailAttachment attachment = emailAttachmentService.findById(id);
String filePath = attachment.getPath()+File.separator+attachment.getNewName();
HttpHeaders headers = new HttpHeaders();
File file = new File(filePath);
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
String fileName = URLEncoder.encode(attachment.getOldName(), "UTF-8");
headers.setContentDispositionFormData("attachment", fileName);
return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file), headers, HttpStatus.OK);
}