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/