Kaynağa Gözat

Update DownloadController.java

Drowsito 1 ay önce
ebeveyn
işleme
826c0837bf

+ 24 - 0
src/main/java/es/uv/saic/web/DownloadController.java

@@ -469,6 +469,30 @@ public class DownloadController {
 		}
 	}
 
+	@GetMapping(value="/download/{idInstancia}/{idTascap}", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
+	@ResponseBody 
+    public ResponseEntity<byte[]> downloadEvidenceByTascaP(@PathVariable("idInstancia") BigInteger idInstancia, @PathVariable("idTascap") Integer idTascap, HttpServletResponse response){
+
+		try {
+			InstanciaTascaDTO i = tc.findInstanciaTascaByInstanciaAndTascaP(idInstancia, idTascap);
+			
+			FileSystemResource file = null;
+
+			file = new FileSystemResource(this.filePath+i.getEvidencia());
+			response.setHeader("Content-Disposition", "attachment; filename="+i.getEvidencia());
+			
+			if (!file.exists()) {
+				return ResponseEntity.ok(new FileSystemResource(this.fileNotFound).getInputStream().readAllBytes());
+			}
+
+			return ResponseEntity.ok(file.getInputStream().readAllBytes());
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+		
+		return null;
+	}
+
 	/*
 	 * Format a value for template insertion
 	 * @param v The value to format