포토 getImage.do 컨트롤러 이동
@aeea59129289209cd6496f97164f9ac147851854
--- src/main/java/kcc/com/cmm/web/EgovFileDownloadController.java
+++ src/main/java/kcc/com/cmm/web/EgovFileDownloadController.java
... | ... | @@ -2,6 +2,7 @@ |
| 2 | 2 |
|
| 3 | 3 |
import java.io.BufferedInputStream; |
| 4 | 4 |
import java.io.BufferedOutputStream; |
| 5 |
+import java.io.ByteArrayOutputStream; |
|
| 5 | 6 |
import java.io.File; |
| 6 | 7 |
import java.io.FileInputStream; |
| 7 | 8 |
import java.io.IOException; |
... | ... | @@ -17,10 +18,12 @@ |
| 17 | 18 |
import org.slf4j.LoggerFactory; |
| 18 | 19 |
import org.springframework.beans.factory.annotation.Value; |
| 19 | 20 |
import org.springframework.stereotype.Controller; |
| 21 |
+import org.springframework.ui.ModelMap; |
|
| 20 | 22 |
import org.springframework.util.FileCopyUtils; |
| 21 | 23 |
import org.springframework.web.bind.annotation.RequestMapping; |
| 22 | 24 |
import org.springframework.web.bind.annotation.RequestParam; |
| 23 | 25 |
|
| 26 |
+import kcc.com.cmm.SessionVO; |
|
| 24 | 27 |
import kcc.com.cmm.service.EgovFileMngService; |
| 25 | 28 |
import kcc.com.cmm.service.FileVO; |
| 26 | 29 |
|
... | ... | @@ -120,7 +123,114 @@ |
| 120 | 123 |
response.setContentType("application/octet-stream;charset=UTF-8");
|
| 121 | 124 |
} |
| 122 | 125 |
} |
| 126 |
+ /** |
|
| 127 |
+ * 첨부된 이미지에 대한 미리보기 기능을 제공한다. |
|
| 128 |
+ * |
|
| 129 |
+ * @param atchFileId |
|
| 130 |
+ * @param fileSn |
|
| 131 |
+ * @param sessionVO |
|
| 132 |
+ * @param model |
|
| 133 |
+ * @param response |
|
| 134 |
+ * @throws Exception |
|
| 135 |
+ */ |
|
| 136 |
+ @SuppressWarnings("resource")
|
|
| 137 |
+ @RequestMapping("/cmm/fms/getImage.do")
|
|
| 138 |
+ public void getImageInf(SessionVO sessionVO, ModelMap model, @RequestParam Map<String, Object> commandMap, HttpServletResponse response) throws Exception {
|
|
| 123 | 139 |
|
| 140 |
+ System.out.println(" :: /cmm/fms/getImage.do ::");
|
|
| 141 |
+ |
|
| 142 |
+ String atchFileId = (String) commandMap.get("atchFileId");
|
|
| 143 |
+ String fileSn = (String) commandMap.get("fileSn");
|
|
| 144 |
+ String isThumbFile = (String) commandMap.get("isThumbFile");
|
|
| 145 |
+ |
|
| 146 |
+ FileVO vo = new FileVO(); |
|
| 147 |
+ |
|
| 148 |
+ vo.setAtchFileId(atchFileId); |
|
| 149 |
+ vo.setFileSn(fileSn); |
|
| 150 |
+ |
|
| 151 |
+ //------------------------------------------------------------ |
|
| 152 |
+ // fileSn이 없는 경우 마지막 파일 참조 |
|
| 153 |
+ //------------------------------------------------------------ |
|
| 154 |
+ if (fileSn == null || fileSn.equals("")) {
|
|
| 155 |
+ int newMaxFileSN = fileService.getMaxFileSN(vo); |
|
| 156 |
+ vo.setFileSn(Integer.toString(newMaxFileSN - 1)); |
|
| 157 |
+ } |
|
| 158 |
+ //------------------------------------------------------------ |
|
| 159 |
+ FileVO fvo = fileService.selectFileInf(vo); |
|
| 160 |
+ |
|
| 161 |
+ String fileNm = fvo.getStreFileNm(); |
|
| 162 |
+ // 섬네일 이미지 경우 |
|
| 163 |
+ if (isThumbFile != null && ("thumbFile").equals(isThumbFile) && fvo.getThumbFileNm() != null) {
|
|
| 164 |
+ fileNm = fvo.getThumbFileNm(); |
|
| 165 |
+ } |
|
| 166 |
+ |
|
| 167 |
+ File file = new File(fvo.getFileStreCours(), fileNm); |
|
| 168 |
+ |
|
| 169 |
+ FileInputStream fis = null; |
|
| 170 |
+ try {
|
|
| 171 |
+ new FileInputStream(file); |
|
| 172 |
+ }catch(Exception e) {}
|
|
| 173 |
+ |
|
| 174 |
+ BufferedInputStream in = null; |
|
| 175 |
+ ByteArrayOutputStream bStream = null; |
|
| 176 |
+ try {
|
|
| 177 |
+ fis = new FileInputStream(file); |
|
| 178 |
+ in = new BufferedInputStream(fis); |
|
| 179 |
+ bStream = new ByteArrayOutputStream(); |
|
| 180 |
+ int imgByte; |
|
| 181 |
+ /*while ((imgByte = in.read()) != -1) {
|
|
| 182 |
+ bStream.write(imgByte); |
|
| 183 |
+ }*/ |
|
| 184 |
+ |
|
| 185 |
+ byte[] outputByte=new byte[104096]; |
|
| 186 |
+ while ((imgByte =in.read(outputByte, 0, 4096 )) > 0 ) {
|
|
| 187 |
+ bStream.write(outputByte,0,imgByte); |
|
| 188 |
+ } |
|
| 189 |
+ String type = ""; |
|
| 190 |
+ if (fvo.getFileExtsn() != null && !"".equals(fvo.getFileExtsn())) {
|
|
| 191 |
+ if ("jpg".equals(fvo.getFileExtsn().toLowerCase())) {
|
|
| 192 |
+ type = "image/jpeg"; |
|
| 193 |
+ } else {
|
|
| 194 |
+ type = "image/" + fvo.getFileExtsn().toLowerCase(); |
|
| 195 |
+ } |
|
| 196 |
+ //type = "image/" + fvo.getFileExtsn().toLowerCase(); |
|
| 197 |
+ |
|
| 198 |
+ } else {
|
|
| 199 |
+ LOGGER.debug("Image fileType is null.");
|
|
| 200 |
+ } |
|
| 201 |
+ |
|
| 202 |
+ response.setHeader("Content-Type", type);
|
|
| 203 |
+ response.setContentLength(bStream.size()); |
|
| 204 |
+ bStream.writeTo(response.getOutputStream()); |
|
| 205 |
+ response.getOutputStream().flush(); |
|
| 206 |
+ response.getOutputStream().close(); |
|
| 207 |
+ |
|
| 208 |
+ } catch (Exception e) {
|
|
| 209 |
+ LOGGER.debug("{}", e);
|
|
| 210 |
+ } finally {
|
|
| 211 |
+ if (bStream != null) {
|
|
| 212 |
+ try {
|
|
| 213 |
+ bStream.close(); |
|
| 214 |
+ } catch (Exception est) {
|
|
| 215 |
+ LOGGER.debug("IGNORED: {}", est.getMessage());
|
|
| 216 |
+ } |
|
| 217 |
+ } |
|
| 218 |
+ if (in != null) {
|
|
| 219 |
+ try {
|
|
| 220 |
+ in.close(); |
|
| 221 |
+ } catch (Exception ei) {
|
|
| 222 |
+ LOGGER.debug("IGNORED: {}", ei.getMessage());
|
|
| 223 |
+ } |
|
| 224 |
+ } |
|
| 225 |
+ if (fis != null) {
|
|
| 226 |
+ try {
|
|
| 227 |
+ fis.close(); |
|
| 228 |
+ } catch (Exception efis) {
|
|
| 229 |
+ LOGGER.debug("IGNORED: {}", efis.getMessage());
|
|
| 230 |
+ } |
|
| 231 |
+ } |
|
| 232 |
+ } |
|
| 233 |
+ } |
|
| 124 | 234 |
/** |
| 125 | 235 |
* 첨부파일로 등록된 파일에 대하여 다운로드를 제공한다. |
| 126 | 236 |
* |
--- src/main/java/kcc/com/cmm/web/EgovImageProcessController.java
+++ src/main/java/kcc/com/cmm/web/EgovImageProcessController.java
... | ... | @@ -46,110 +46,5 @@ |
| 46 | 46 |
|
| 47 | 47 |
private static final Logger LOGGER = LoggerFactory.getLogger(EgovImageProcessController.class); |
| 48 | 48 |
|
| 49 |
- /** |
|
| 50 |
- * 첨부된 이미지에 대한 미리보기 기능을 제공한다. |
|
| 51 |
- * |
|
| 52 |
- * @param atchFileId |
|
| 53 |
- * @param fileSn |
|
| 54 |
- * @param sessionVO |
|
| 55 |
- * @param model |
|
| 56 |
- * @param response |
|
| 57 |
- * @throws Exception |
|
| 58 |
- */ |
|
| 59 |
- @SuppressWarnings("resource")
|
|
| 60 |
- @RequestMapping("/cmm/fms/getImage.do")
|
|
| 61 |
- public void getImageInf(SessionVO sessionVO, ModelMap model, @RequestParam Map<String, Object> commandMap, HttpServletResponse response) throws Exception {
|
|
| 62 |
- |
|
| 63 |
- String atchFileId = (String) commandMap.get("atchFileId");
|
|
| 64 |
- String fileSn = (String) commandMap.get("fileSn");
|
|
| 65 |
- String isThumbFile = (String) commandMap.get("isThumbFile");
|
|
| 66 |
- |
|
| 67 |
- FileVO vo = new FileVO(); |
|
| 68 |
- |
|
| 69 |
- vo.setAtchFileId(atchFileId); |
|
| 70 |
- vo.setFileSn(fileSn); |
|
| 71 |
- |
|
| 72 |
- //------------------------------------------------------------ |
|
| 73 |
- // fileSn이 없는 경우 마지막 파일 참조 |
|
| 74 |
- //------------------------------------------------------------ |
|
| 75 |
- if (fileSn == null || fileSn.equals("")) {
|
|
| 76 |
- int newMaxFileSN = fileService.getMaxFileSN(vo); |
|
| 77 |
- vo.setFileSn(Integer.toString(newMaxFileSN - 1)); |
|
| 78 |
- } |
|
| 79 |
- //------------------------------------------------------------ |
|
| 80 |
- FileVO fvo = fileService.selectFileInf(vo); |
|
| 81 |
- |
|
| 82 |
- String fileNm = fvo.getStreFileNm(); |
|
| 83 |
- // 섬네일 이미지 경우 |
|
| 84 |
- if (isThumbFile != null && ("thumbFile").equals(isThumbFile) && fvo.getThumbFileNm() != null) {
|
|
| 85 |
- fileNm = fvo.getThumbFileNm(); |
|
| 86 |
- } |
|
| 87 |
- |
|
| 88 |
- File file = new File(fvo.getFileStreCours(), fileNm); |
|
| 89 |
- |
|
| 90 |
- FileInputStream fis = null; |
|
| 91 |
- try {
|
|
| 92 |
- new FileInputStream(file); |
|
| 93 |
- }catch(Exception e) {}
|
|
| 94 |
- |
|
| 95 |
- BufferedInputStream in = null; |
|
| 96 |
- ByteArrayOutputStream bStream = null; |
|
| 97 |
- try {
|
|
| 98 |
- fis = new FileInputStream(file); |
|
| 99 |
- in = new BufferedInputStream(fis); |
|
| 100 |
- bStream = new ByteArrayOutputStream(); |
|
| 101 |
- int imgByte; |
|
| 102 |
- /*while ((imgByte = in.read()) != -1) {
|
|
| 103 |
- bStream.write(imgByte); |
|
| 104 |
- }*/ |
|
| 105 |
- |
|
| 106 |
- byte[] outputByte=new byte[104096]; |
|
| 107 |
- while ((imgByte =in.read(outputByte, 0, 4096 )) > 0 ) {
|
|
| 108 |
- bStream.write(outputByte,0,imgByte); |
|
| 109 |
- } |
|
| 110 |
- String type = ""; |
|
| 111 |
- if (fvo.getFileExtsn() != null && !"".equals(fvo.getFileExtsn())) {
|
|
| 112 |
- if ("jpg".equals(fvo.getFileExtsn().toLowerCase())) {
|
|
| 113 |
- type = "image/jpeg"; |
|
| 114 |
- } else {
|
|
| 115 |
- type = "image/" + fvo.getFileExtsn().toLowerCase(); |
|
| 116 |
- } |
|
| 117 |
- //type = "image/" + fvo.getFileExtsn().toLowerCase(); |
|
| 118 |
- |
|
| 119 |
- } else {
|
|
| 120 |
- LOGGER.debug("Image fileType is null.");
|
|
| 121 |
- } |
|
| 122 |
- |
|
| 123 |
- response.setHeader("Content-Type", type);
|
|
| 124 |
- response.setContentLength(bStream.size()); |
|
| 125 |
- bStream.writeTo(response.getOutputStream()); |
|
| 126 |
- response.getOutputStream().flush(); |
|
| 127 |
- response.getOutputStream().close(); |
|
| 128 |
- |
|
| 129 |
- } catch (Exception e) {
|
|
| 130 |
- LOGGER.debug("{}", e);
|
|
| 131 |
- } finally {
|
|
| 132 |
- if (bStream != null) {
|
|
| 133 |
- try {
|
|
| 134 |
- bStream.close(); |
|
| 135 |
- } catch (Exception est) {
|
|
| 136 |
- LOGGER.debug("IGNORED: {}", est.getMessage());
|
|
| 137 |
- } |
|
| 138 |
- } |
|
| 139 |
- if (in != null) {
|
|
| 140 |
- try {
|
|
| 141 |
- in.close(); |
|
| 142 |
- } catch (Exception ei) {
|
|
| 143 |
- LOGGER.debug("IGNORED: {}", ei.getMessage());
|
|
| 144 |
- } |
|
| 145 |
- } |
|
| 146 |
- if (fis != null) {
|
|
| 147 |
- try {
|
|
| 148 |
- fis.close(); |
|
| 149 |
- } catch (Exception efis) {
|
|
| 150 |
- LOGGER.debug("IGNORED: {}", efis.getMessage());
|
|
| 151 |
- } |
|
| 152 |
- } |
|
| 153 |
- } |
|
| 154 |
- } |
|
| 49 |
+ |
|
| 155 | 50 |
} |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?