diff --git a/src/main/java/seed/com/gtm/seedfile/FileDownloadView.java b/src/main/java/seed/com/gtm/seedfile/FileDownloadView.java new file mode 100644 index 00000000..e2f7abcc --- /dev/null +++ b/src/main/java/seed/com/gtm/seedfile/FileDownloadView.java @@ -0,0 +1,85 @@ +package seed.com.gtm.seedfile; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.OutputStream; +import java.io.UnsupportedEncodingException; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.util.FileCopyUtils; +import org.springframework.web.servlet.view.AbstractView; + + +public class FileDownloadView extends AbstractView { + + public FileDownloadView(){ + setContentType("application/download; charset=utf-8"); + } + + @Override + protected void renderMergedOutputModel(Map map, + HttpServletRequest request, HttpServletResponse response) throws Exception { + + boolean success = false; + String fileReName = (String)map.get("fileReName"); + String fileName = (String)map.get("fileName"); + String filePath = (String)map.get("filePath"); + + + try{ + if(!"".equals(fileReName)){ + + File file = null; + FileInputStream fin = null; + OutputStream out = null; + try{ + + file = new File(filePath, fileReName); + + response.setContentType(getContentType()); + response.setContentLength((int)file.length()); + + String client = request.getHeader("User-Agent"); + + + if(client.indexOf("MSIE") != -1 || client.indexOf("Trident") != -1){ + response.setHeader ("Content-Disposition", "attachment; filename="+new String(fileName.getBytes("KSC5601"),"ISO8859_1")); + }else{ + fileName = new String(fileName.getBytes("utf-8"),"iso-8859-1"); + response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\""); + } + + response.setHeader("Content-Transfer-Encoding", "binary"); + + out = response.getOutputStream(); + fin = new FileInputStream(file); + + FileCopyUtils.copy(fin, out); + + }catch(UnsupportedEncodingException e){ + System.out.println("UnsupportedEncodingException Error"); + }catch(FileNotFoundException e){ + System.out.println("FileNotFoundException Error"); + }catch(IOException e){ + System.out.println("IOException Error"); + }catch(Exception e){ + System.out.println("Exception Error"); + }finally{ + if(fin!=null)try{fin.close();}catch(Exception e){} + if(out!=null)try{out.close();}catch(Exception e){} + } + } + }catch(NullPointerException e){ + System.out.println("download.jsp 파일에서 에러 발생 NullPointerException"); + }catch(ArrayIndexOutOfBoundsException e){ + System.out.println("download.jsp 파일 부분 에러 발생 ArrayIndexOutOfBoundsException"); + }finally{ + + } + } +} diff --git a/src/main/java/seed/com/gtm/seedfile/SeedFileController.java b/src/main/java/seed/com/gtm/seedfile/SeedFileController.java index 3fc82c07..c0b3471e 100644 --- a/src/main/java/seed/com/gtm/seedfile/SeedFileController.java +++ b/src/main/java/seed/com/gtm/seedfile/SeedFileController.java @@ -217,7 +217,7 @@ public class SeedFileController { SeedProperties seedProperties = new SeedProperties(); /*String rootPath = seedProperties.getConfigValue("file.real.path");*/ - String rootPath = globalRootPath; + String rootPath = globalRealPath; String dataIdx = SeedUtils.setReplaceNull(paramMap.get("dataIdx")); String pathKey1 = SeedUtils.setReplaceNull(paramMap.get("pathKey1")); diff --git a/src/main/java/seed/com/gtm/seedfile/SeedFileService.java b/src/main/java/seed/com/gtm/seedfile/SeedFileService.java index 42998bc9..71c1c241 100644 --- a/src/main/java/seed/com/gtm/seedfile/SeedFileService.java +++ b/src/main/java/seed/com/gtm/seedfile/SeedFileService.java @@ -1,6 +1,7 @@ package seed.com.gtm.seedfile; import java.io.File; +import java.io.IOException; import java.util.Date; import java.util.List; import java.util.Map; @@ -79,8 +80,7 @@ public class SeedFileService { String toDate = seedDateUtil.getSimpleDateFormat(new Date(), "yyyyMMdd"); String renameDate = seedDateUtil.getSimpleDateFormat(new Date(), "yyyyMMddHHmmss"); - /*SeedUtils.setSeedMkDirs(rootPath + "/"+siteIdx+ "/" +fileFuncType);*/ - SeedUtils.setSeedMkDirs(rootPath + "/"+siteIdx+ fileFuncType); + SeedUtils.setSeedMkDirs(rootPath + "/"+siteIdx+"/"+ fileFuncType); int fileCnt = 0; @@ -118,6 +118,21 @@ public class SeedFileService { filePath = rootPath + "/"+siteIdx+"/upload/uploadFiles/"+fileFuncType+"/"+reFileName+"."+fileType; }else{ + + //241029 - 첨부파일 복사를 위해 real 파일 생성 처리 +/* File makeFile = null; + makeFile = new File(rootPath + "/"+siteIdx+"/"+fileFuncType+"/"+reFileName); + if(! makeFile.exists()){ + //경로에 해당하는 디렉토리들을 생성 + if(makeFile.getParentFile().mkdirs()){ + try { + makeFile.createNewFile(); //이후 파일 생성 + } catch (IOException e) { + // TODO Auto-generated catch block + } + } + }*/ + SeedUtils.setSeedFileCopy(tempPath + "/"+siteIdx+"/"+fileFuncType + "/" + uploadFileReNameData, rootPath + "/"+siteIdx+"/"+fileFuncType+"/"+reFileName+"."+fileType); diff --git a/src/main/java/seed/utils/SeedUtils.java b/src/main/java/seed/utils/SeedUtils.java index 77c06ffc..9a43b483 100644 --- a/src/main/java/seed/utils/SeedUtils.java +++ b/src/main/java/seed/utils/SeedUtils.java @@ -202,7 +202,7 @@ public class SeedUtils { * Was=서버파일관리 권한이 완전 동일 해야함 * @param String dirPath 폴더 경로 */ - public static void setSeedMkDirs(String dirPath){ + /*public static void setSeedMkDirs(String dirPath){ File file = new File(dirPath); @@ -213,7 +213,17 @@ public class SeedUtils { if(!file.exists()){ file.mkdirs(); } - } + }*/ + + public static void setSeedMkDirs(String dirPath) { + File file = new File(dirPath); + if (!file.exists() && !file.isDirectory()) { + if (!file.exists()) { + file.mkdirs(); + } + + } + } public static void setSeedFileCopy(String inFileName, String outFileName){ diff --git a/src/main/webapp/WEB-INF/config/egovframework/springmvc/egov-com-servlet.xml b/src/main/webapp/WEB-INF/config/egovframework/springmvc/egov-com-servlet.xml index 12e16bb6..f5f07e91 100644 --- a/src/main/webapp/WEB-INF/config/egovframework/springmvc/egov-com-servlet.xml +++ b/src/main/webapp/WEB-INF/config/egovframework/springmvc/egov-com-servlet.xml @@ -43,6 +43,9 @@ + + +