From e21c405437406b9931573730e86a5c8b076fac85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EC=84=9D=20=EC=B5=9C?= Date: Mon, 14 Nov 2022 17:39:55 +0900 Subject: [PATCH] =?UTF-8?q?=EC=97=90=EB=94=94=ED=84=B0=20=EC=82=AC?= =?UTF-8?q?=EC=A7=84=20=EC=97=85=EB=A1=9C=EB=93=9C=20=EC=A4=91=EA=B0=84?= =?UTF-8?q?=EC=A0=80=EC=9E=A5.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dbnt/faisp/config/EditorController.java | 8 ++++-- .../com/dbnt/faisp/config/FileController.java | 28 +++++++++++++++++++ .../resources/application-test.properties | 3 +- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/dbnt/faisp/config/EditorController.java b/src/main/java/com/dbnt/faisp/config/EditorController.java index 92df4ea2..58243fb1 100644 --- a/src/main/java/com/dbnt/faisp/config/EditorController.java +++ b/src/main/java/com/dbnt/faisp/config/EditorController.java @@ -50,6 +50,8 @@ public class EditorController { @Value("${file.dir}") protected String fileDir; + @Value("${file.dir.editor}") + protected String editorPath; @Autowired private Environment env; @@ -72,7 +74,7 @@ public class EditorController { String extNm = "." + attach_file_Name.substring( attach_file_Name.lastIndexOf( "." ) + 1, attach_file_Name.length()); if(".jpg,.png,.jpeg".indexOf(extNm.toLowerCase()) > -1) { - File dir = new File(fileDir + year); + File dir = new File(fileDir+File.separator+editorPath); if (!dir.exists()) { try{ @@ -91,10 +93,10 @@ public class EditorController { System.out.println("Directory already exists"); } - File file = new File(fileDir + year, attach_save_Name + extNm); + File file = new File(fileDir+File.separator+editorPath, attach_save_Name + extNm); FileCopyUtils.copy(mFile.getBytes(), file); - String webPath = "http://localhost:8080/" + fileDir + year + attach_save_Name + extNm; + String webPath = "http://localhost:8080/file/editorFileDisplay?fileNm=" + attach_save_Name + extNm; result.set("result", "success"); List addmsg = new ArrayList<>(); diff --git a/src/main/java/com/dbnt/faisp/config/FileController.java b/src/main/java/com/dbnt/faisp/config/FileController.java index bc002467..3009c48a 100644 --- a/src/main/java/com/dbnt/faisp/config/FileController.java +++ b/src/main/java/com/dbnt/faisp/config/FileController.java @@ -9,6 +9,7 @@ import com.dbnt.faisp.main.fpiMgt.affairResult.service.ResultService; import com.dbnt.faisp.main.ivsgtMgt.boardInvestigation.service.BoardInvestigationService; import com.dbnt.faisp.main.publicBoard.service.PublicBoardService; import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Value; import org.springframework.core.io.FileSystemResource; import org.springframework.core.io.Resource; import org.springframework.http.HttpHeaders; @@ -40,6 +41,32 @@ public class FileController { private final BoardInvestigationService boardInvestigationService; private final FishingBoatService fishingBoatService; + @Value("${file.dir}") + protected String fileDir; + @Value("${file.dir.editor}") + protected String editorPath; + + @GetMapping("/editorFileDisplay") + public ResponseEntity editorFileDisplay(HttpServletRequest request, + HttpServletResponse response, + String fileNm) { + + String pathStr = fileDir+File.separator+editorPath+File.separator+fileNm; + Resource resource = new FileSystemResource(pathStr); + if(!resource.exists()){ + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } + HttpHeaders header = new HttpHeaders(); + Path filePath = null; + try { + filePath = Paths.get(pathStr); + header.add("Content-type", Files.probeContentType(filePath)); + }catch (IOException e){ + e.printStackTrace(); + } + return new ResponseEntity(resource, header, HttpStatus.OK); + } + @GetMapping("/fileDisplay") public ResponseEntity fileDisplay(HttpServletRequest request, HttpServletResponse response, @@ -62,6 +89,7 @@ public class FileController { } return new ResponseEntity(resource, header, HttpStatus.OK); } + @GetMapping("/fileDownload") public void fileDownload(HttpServletRequest request, HttpServletResponse response, diff --git a/src/main/resources/application-test.properties b/src/main/resources/application-test.properties index c6b85482..721a2dd6 100644 --- a/src/main/resources/application-test.properties +++ b/src/main/resources/application-test.properties @@ -6,12 +6,13 @@ spring.servlet.multipart.max-file-size=200MB spring.servlet.multipart.max-request-size=500MB #file -file.dir=C:\\faispUploadFiles +file.dir=/docker/faisp/uploadFiles file.dir.vulnerable=/vulnerable file.dir.part=/part file.dir.equip=/equip file.dir.sailor=sailor file.dir.affair=affair +file.dir.editor=editor #thymeleaf spring.thymeleaf.prefix=classpath:templates/