|
|
@@ -61,8 +61,16 @@ public class DownloadController {
|
|
|
*/
|
|
|
@GetMapping(value="/download/document/{id}", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
|
|
|
@ResponseBody
|
|
|
- public FileSystemResource downloadDocument(Model model, @PathVariable("id") Integer idDocument) throws FileNotFoundException {
|
|
|
- return dc.downloadDocument(idDocument).getBody();
|
|
|
+ public FileSystemResource downloadDocument(Model model, @PathVariable("id") Integer idDocument) throws IOException {
|
|
|
+ ResponseEntity<byte[]> response = dc.downloadDocument(idDocument);
|
|
|
+ byte[] data = response.getBody();
|
|
|
+ String fileName = response.getHeaders().getFirst("Content-Disposition").split("filename=")[1].replace("\"", "");
|
|
|
+
|
|
|
+ Path tempFile = Files.createTempFile( "download-", "-" + fileName);
|
|
|
+ Files.write(tempFile, data);
|
|
|
+ tempFile.toFile().deleteOnExit();
|
|
|
+
|
|
|
+ return new FileSystemResource(tempFile.toFile());
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
@@ -76,7 +84,15 @@ public class DownloadController {
|
|
|
@GetMapping(value="/download/report/{t}/{p}", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
|
|
|
@ResponseBody
|
|
|
public FileSystemResource downloadReport(Model model, @PathVariable("t") Integer idTitulacio, @PathVariable("p") String nomProces) throws IOException, XDocReportException {
|
|
|
- return dc.downloadReport(idTitulacio, nomProces).getBody();
|
|
|
+ ResponseEntity<byte[]> response = dc.downloadReport(idTitulacio, nomProces);
|
|
|
+ byte[] data = response.getBody();
|
|
|
+ String fileName = response.getHeaders().getFirst("Content-Disposition").split("filename=")[1].replace("\"", "");
|
|
|
+
|
|
|
+ Path tempFile = Files.createTempFile( "download-", "-" + fileName);
|
|
|
+ Files.write(tempFile, data);
|
|
|
+ tempFile.toFile().deleteOnExit();
|
|
|
+
|
|
|
+ return new FileSystemResource(tempFile.toFile());
|
|
|
}
|
|
|
|
|
|
|