// 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");
    }
  }
  // add arquivo
  @RequestMapping(method = RequestMethod.POST)
  public @ResponseBody Long handleFileUpload(@RequestParam("file") MultipartFile file) {

    log.debug("Documento - POST");
    if (!file.isEmpty()) {
      try {
        if (file.getBytes() != null && file.getBytes().length != 0) {
          Documento documento = new Documento();
          documento.setArquivo(file.getBytes());
          documento.setNome(file.getOriginalFilename());
          documento.setNomeOriginal(file.getOriginalFilename());
          documento.setTipo(file.getContentType());
          serviceDocumento.save(documento);
          // retornar o ID do documento
          return documento.getId();
        }
      } catch (IOException ioe) {
        return (long) -1;
      }
    }
    return (long) -1;
  }