|
|
@@ -3,11 +3,15 @@ package es.uv.saic.web;
|
|
|
import java.io.FileNotFoundException;
|
|
|
import java.io.IOException;
|
|
|
import java.math.BigInteger;
|
|
|
+import java.nio.file.Files;
|
|
|
+import java.nio.file.Path;
|
|
|
import java.util.Optional;
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.core.io.FileSystemResource;
|
|
|
import org.springframework.http.MediaType;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.ui.Model;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
@@ -19,6 +23,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
import es.uv.saic.dto.PdfDTO;
|
|
|
import es.uv.saic.feign.DocumentClient;
|
|
|
import fr.opensagres.xdocreport.core.XDocReportException;
|
|
|
+import jakarta.servlet.http.HttpServletResponse;
|
|
|
|
|
|
@Controller
|
|
|
public class DownloadController {
|
|
|
@@ -34,8 +39,18 @@ public class DownloadController {
|
|
|
*/
|
|
|
@GetMapping(value="/download/{fileName}", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
|
|
|
@ResponseBody
|
|
|
- public byte[] download(Model model, @PathVariable("fileName") BigInteger idInstanciaTasca) throws FileNotFoundException {
|
|
|
- return dc.download(idInstanciaTasca);
|
|
|
+ public FileSystemResource download(Model model, @PathVariable("fileName") BigInteger idInstanciaTasca) throws IOException {
|
|
|
+ // Convert byte[] to FileSystemResource
|
|
|
+ ResponseEntity<byte[]> response = dc.download(idInstanciaTasca);
|
|
|
+ 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());
|
|
|
}
|
|
|
|
|
|
/*
|