Ejemplo n.º 1
0
  // 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");
    }
  }
Ejemplo n.º 2
0
 // get by id
 @RequestMapping(value = "{id}", method = RequestMethod.GET)
 public @ResponseBody Documento findById(@PathVariable Integer id) {
   log.debug("Documento - GET (id)");
   return serviceDocumento.find(Documento.class, (long) id);
 }
Ejemplo n.º 3
0
 // listar arquivos
 @RequestMapping(method = RequestMethod.GET)
 public @ResponseBody List<Documento> findAll() {
   log.debug("Documento - GET (all)");
   return serviceDocumento.find(Documento.class);
 }