에디터 사진 업로드 중간저장.

강석 최 2022-11-14 17:39:55 +09:00
parent d9cd77b905
commit e21c405437
3 changed files with 35 additions and 4 deletions

View File

@ -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<ParamMap> addmsg = new ArrayList<>();

View File

@ -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<Resource> 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>(resource, header, HttpStatus.OK);
}
@GetMapping("/fileDisplay")
public ResponseEntity<Resource> fileDisplay(HttpServletRequest request,
HttpServletResponse response,
@ -62,6 +89,7 @@ public class FileController {
}
return new ResponseEntity<Resource>(resource, header, HttpStatus.OK);
}
@GetMapping("/fileDownload")
public void fileDownload(HttpServletRequest request,
HttpServletResponse response,

View File

@ -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/