0
I have a datatable and I want to implement a download button to download the pdf file from that specific line. I already managed to implement p:fileUpload and now I want to download this uploaded file.
My upload method
public void upload(FileUploadEvent evento) {
try {
UploadedFile arquivoUpload = evento.getFile();
Path arquivoTemp = Files.createTempFile(null, null);
Files.copy(arquivoUpload.getInputstream(), arquivoTemp, StandardCopyOption.REPLACE_EXISTING);
monografia.setCaminho(arquivoTemp.toString());
Messages.addGlobalInfo("Upload realizado com sucesso");
} catch (IOException erro) {
Messages.addGlobalInfo("Ocorreu um erro ao tentar realizar o upload de arquivo");
erro.printStackTrace();
}
}
Method salvar
public void salvar(){
try {
Path origem = Paths.get(monografia.getCaminho());
Path destino = Paths.get("C:/Uploads/Monografia/" + monografia.getTitulo() + ".pdf");
Files.copy(origem, destino, StandardCopyOption.REPLACE_EXISTING);
cadastroMonografiaService.salvar(monografia);
atualizarRegistros();
messages.info("Monografia salva com sucesso!");
RequestContext.getCurrentInstance().update(Arrays.asList("frm:monografiasDataTable", "frm:messages"));
} catch (Exception erro) {
messages.alerta("Erro ao salvar a Monografia!");
erro.printStackTrace();
}
}
This thing you posted at the showcase, but I couldn’t do it. I will post my method where I save the file in a specific directory, now what I want is to get this file that will be in this directory, from the specific monograph that will be selected in the datatable
– Daniel Azevedo