From da6920107b468b1b54b35d845da777431906f779 Mon Sep 17 00:00:00 2001 From: KNKIM Date: Mon, 26 Jul 2021 10:28:56 +0900 Subject: [PATCH] =?UTF-8?q?=EC=9E=AC=EC=BB=A4=EB=B0=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cmm/fileupload/FileUploadController.java | 372 +++++++++--------- .../nlib/cmm/fileupload/FileUploadDomain.java | 82 ++-- 2 files changed, 227 insertions(+), 227 deletions(-) diff --git a/src/main/java/nlib/cmm/fileupload/FileUploadController.java b/src/main/java/nlib/cmm/fileupload/FileUploadController.java index 7b169677..e06d2e1f 100644 --- a/src/main/java/nlib/cmm/fileupload/FileUploadController.java +++ b/src/main/java/nlib/cmm/fileupload/FileUploadController.java @@ -1,186 +1,186 @@ -package nlib.cmm.fileupload; - -import java.io.File; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -import javax.annotation.Resource; -import javax.servlet.http.HttpServletResponse; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.multipart.MultipartFile; -import org.springframework.web.multipart.MultipartHttpServletRequest; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; - -import egovframework.com.cmm.EgovWebUtil; -import egovframework.com.cmm.service.FileVO; -import nlib.cmm.exception.ErrorMessage; -import nlib.cmm.service.NlibProperty; -import nlib.util.FileUtil; -import nlib.util.StringUtil; -import nlib.util.UUID; - -/** - *
- * @Class Name : FileUploadController.java
- * 
- * @Description : 파일 업로드를 처리하는 컨트롤러  
- * 
- * 
- * @프로젝트명: 지방문화원 통합자료관리시스템 구축사업 (2021)
- *
- * 
- * - * @ ------------ -------- --------------------------- - * @ 수정일 수정자 수정내용 - * @ ------------ -------- --------------------------- - * @ 2021. 7. 15. KNKIM 최초 생성 - * - * - * @author 이씨플라자 * DIGITALSHIP KNKIM - * @since 2021. 7. 15. - * @version 1.0 - * - */ -@Controller -public class FileUploadController { - - private static final Logger log = LoggerFactory.getLogger(FileUploadController.class); - - @Resource(name="nlibProperty") - NlibProperty nlibProperty; - - - /** - * 첨부파일이 저장되는 최상위 위치 - */ - @Value("#{properties['fileupload.base.path']}") - private String FILEUPLOAD_BASE_PATH; - - /** - * 첨부파일 임시 저장 위치 - */ - @Value("#{properties['fileupload.temp.subpath']}") - private String FILEUPLOAD_TEMP_SUBPATH; - - @ResponseBody - @RequestMapping(value="/fileupload/uploadFilesAjax.do", produces="application/json") - public ResponseEntity uploadFilesAjax( - final MultipartHttpServletRequest multiRequest - , @RequestParam("subPathKey") String subPathKey - , HttpServletResponse response) { - - // TODO : 권한 체크 추가할 것 - - List result = new ArrayList(); - - try { - - // 최상위 위치 - if(FileUtil.isNotValid(FILEUPLOAD_BASE_PATH)) throw new Exception("첨부파일이 저장되는 최상위 위치값이 적절하지 않습니다."); - - // 서브 위치 - if(StringUtil.isEmpty(subPathKey)) throw new Exception("첨부파일이 저장되는 위치정보값이 정확하지 않습니다."); - String subPath = nlibProperty.getProperty(subPathKey); - if(FileUtil.isNotValid(subPath)) throw new Exception("첨부파일 서브 위치값이 적절하지 않습니다."); - - final Map files = multiRequest.getFileMap(); - log.debug("uploadFilesAjax : 진입 " + (files == null ? " files null " : files.size())); - - File dir = new File(FILEUPLOAD_BASE_PATH + subPath); - if(!dir.exists() || !dir.isDirectory()) dir.mkdirs(); - - if(!files.isEmpty()) { - - Iterator> itr = files.entrySet().iterator(); - MultipartFile file; - String filePath = ""; - FileVO fvo; - - int fileKey = 1; - while (itr.hasNext()) { - Entry entry = itr.next(); - - file = entry.getValue(); - String orginFileName = file.getOriginalFilename(); - - //-------------------------------------- - // 원 파일명이 없는 경우 처리 - // (첨부가 되지 않은 input file type) - //-------------------------------------- - if ("".equals(orginFileName)) { - continue; - } - ////------------------------------------ - - int index = orginFileName.lastIndexOf("."); - //String fileName = orginFileName.substring(0, index); - String fileExt = orginFileName.substring(index + 1); - //String newName = KeyStr + getTimeStamp() + fileKey; - String newName = UUID.getPhysicalFileName(); - long size = file.getSize(); - - log.debug("FILE UPLOAD : File New Name=" + newName); - - if (!"".equals(orginFileName)) { - filePath = FILEUPLOAD_BASE_PATH + subPath + "/" + newName; - log.debug("FILE UPLOAD : filePath=" + filePath); - - file.transferTo(new File(EgovWebUtil.filePathBlackList(filePath))); - } - - fvo = new FileVO(); - fvo.setFileExtsn(fileExt); - //fvo.setFileStreCours(storePathString); - fvo.setFileMg(Long.toString(size)); - fvo.setOrignlFileNm(orginFileName); - fvo.setStreFileNm(newName); - //fvo.setAtchFileId(atchFileIdString); - fvo.setFileSn(String.valueOf(fileKey)); - - result.add(fvo); - - fileKey++; - } - } - } catch(Exception e) { - ErrorMessage errorMessage = new ErrorMessage("ERROR", "처리에 실패하였습니다 : " + e.toString()); - e.printStackTrace(); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(errorMessage); - } - - // Convert Json - ObjectMapper mapper = new ObjectMapper(); - String json; - try { - json = mapper.writeValueAsString(result); - log.debug("RETURN DATA > json:" + json); - } catch (JsonProcessingException e) { - json = null; - e.printStackTrace(); - } - - HttpHeaders responseHeaders = new HttpHeaders(); - //responseHeaders.set("Content-Type", "application/json; charset=UTF-8"); - - ResponseEntity ret = ResponseEntity.ok().headers(responseHeaders).body(json); - return ret; - } - -} - +package nlib.cmm.fileupload; + +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.multipart.MultipartHttpServletRequest; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +import egovframework.com.cmm.EgovWebUtil; +import egovframework.com.cmm.service.FileVO; +import nlib.cmm.exception.ErrorMessage; +import nlib.cmm.service.NlibProperty; +import nlib.util.FileUtil; +import nlib.util.StringUtil; +import nlib.util.UUID; + +/** + *
+ * @Class Name : FileUploadController.java
+ * 
+ * @Description : 파일 업로드를 처리하는 컨트롤러  
+ * 
+ * 
+ * @프로젝트명: 지방문화원 통합자료관리시스템 구축사업 (2021)
+ *
+ * 
+ * + * @ ------------ -------- --------------------------- + * @ 수정일 수정자 수정내용 + * @ ------------ -------- --------------------------- + * @ 2021. 7. 15. KNKIM 최초 생성 + * + * + * @author 이씨플라자 * DIGITALSHIP KNKIM + * @since 2021. 7. 15. + * @version 1.0 + * + */ +@Controller +public class FileUploadController { + + private static final Logger log = LoggerFactory.getLogger(FileUploadController.class); + + @Resource(name="nlibProperty") + NlibProperty nlibProperty; + + + /** + * 첨부파일이 저장되는 최상위 위치 + */ + @Value("#{properties['fileupload.base.path']}") + private String FILEUPLOAD_BASE_PATH; + + /** + * 첨부파일 임시 저장 위치 + */ + @Value("#{properties['fileupload.temp.subpath']}") + private String FILEUPLOAD_TEMP_SUBPATH; + + @ResponseBody + @RequestMapping(value="/fileupload/uploadFilesAjax.do", produces="application/json") + public ResponseEntity uploadFilesAjax( + final MultipartHttpServletRequest multiRequest + , @RequestParam("subPathKey") String subPathKey + , HttpServletResponse response) { + + // TODO : 권한 체크 추가할 것 + + List result = new ArrayList(); + + try { + + // 최상위 위치 + if(FileUtil.isNotValid(FILEUPLOAD_BASE_PATH)) throw new Exception("첨부파일이 저장되는 최상위 위치값이 적절하지 않습니다."); + + // 서브 위치 + if(StringUtil.isEmpty(subPathKey)) throw new Exception("첨부파일이 저장되는 위치정보값이 정확하지 않습니다."); + String subPath = nlibProperty.getProperty(subPathKey); + if(FileUtil.isNotValid(subPath)) throw new Exception("첨부파일 서브 위치값이 적절하지 않습니다."); + + final Map files = multiRequest.getFileMap(); + log.debug("uploadFilesAjax : 진입 " + (files == null ? " files null " : files.size())); + + File dir = new File(FILEUPLOAD_BASE_PATH + subPath); + if(!dir.exists() || !dir.isDirectory()) dir.mkdirs(); + + if(!files.isEmpty()) { + + Iterator> itr = files.entrySet().iterator(); + MultipartFile file; + String filePath = ""; + FileVO fvo; + + int fileKey = 1; + while (itr.hasNext()) { + Entry entry = itr.next(); + + file = entry.getValue(); + String orginFileName = file.getOriginalFilename(); + + //-------------------------------------- + // 원 파일명이 없는 경우 처리 + // (첨부가 되지 않은 input file type) + //-------------------------------------- + if ("".equals(orginFileName)) { + continue; + } + ////------------------------------------ + + int index = orginFileName.lastIndexOf("."); + //String fileName = orginFileName.substring(0, index); + String fileExt = orginFileName.substring(index + 1); + //String newName = KeyStr + getTimeStamp() + fileKey; + String newName = UUID.getPhysicalFileName(); + long size = file.getSize(); + + log.debug("FILE UPLOAD : File New Name=" + newName); + + if (!"".equals(orginFileName)) { + filePath = FILEUPLOAD_BASE_PATH + subPath + "/" + newName; + log.debug("FILE UPLOAD : filePath=" + filePath); + + file.transferTo(new File(EgovWebUtil.filePathBlackList(filePath))); + } + + fvo = new FileVO(); + fvo.setFileExtsn(fileExt); + //fvo.setFileStreCours(storePathString); + fvo.setFileMg(Long.toString(size)); + fvo.setOrignlFileNm(orginFileName); + fvo.setStreFileNm(newName); + //fvo.setAtchFileId(atchFileIdString); + fvo.setFileSn(String.valueOf(fileKey)); + + result.add(fvo); + + fileKey++; + } + } + } catch(Exception e) { + ErrorMessage errorMessage = new ErrorMessage("ERROR", "처리에 실패하였습니다 : " + e.toString()); + e.printStackTrace(); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(errorMessage); + } + + // Convert Json + ObjectMapper mapper = new ObjectMapper(); + String json; + try { + json = mapper.writeValueAsString(result); + log.debug("RETURN DATA > json:" + json); + } catch (JsonProcessingException e) { + json = null; + e.printStackTrace(); + } + + HttpHeaders responseHeaders = new HttpHeaders(); + //responseHeaders.set("Content-Type", "application/json; charset=UTF-8"); + + ResponseEntity ret = ResponseEntity.ok().headers(responseHeaders).body(json); + return ret; + } + +} + diff --git a/src/main/java/nlib/cmm/fileupload/FileUploadDomain.java b/src/main/java/nlib/cmm/fileupload/FileUploadDomain.java index a7d078e4..27eb4658 100644 --- a/src/main/java/nlib/cmm/fileupload/FileUploadDomain.java +++ b/src/main/java/nlib/cmm/fileupload/FileUploadDomain.java @@ -1,41 +1,41 @@ -package nlib.cmm.fileupload; - -import java.io.Serializable; -import java.util.List; - -import org.springframework.web.multipart.MultipartFile; - -public class FileUploadDomain implements Serializable { - - private String name; - - private String description; - - private List images; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public List getImages() { - return images; - } - - public void setImages(List images) { - this.images = images; - } - - -} +package nlib.cmm.fileupload; + +import java.io.Serializable; +import java.util.List; + +import org.springframework.web.multipart.MultipartFile; + +public class FileUploadDomain implements Serializable { + + private String name; + + private String description; + + private List images; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public List getImages() { + return images; + } + + public void setImages(List images) { + this.images = images; + } + + +}