From b834a3ca40c8e11b2f12d184af8152955cbffa0c Mon Sep 17 00:00:00 2001 From: SeoJin Kim Date: Wed, 2 Jun 2021 01:29:10 +0900 Subject: [PATCH] =?UTF-8?q?[Spring][=EC=87=BC=ED=95=91=EB=AA=B0=20?= =?UTF-8?q?=ED=94=84=EB=A1=9C=EC=A0=9D=ED=8A=B8][26]=20=EC=97=85=EB=A1=9C?= =?UTF-8?q?=EB=93=9C=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EC=82=AD=EC=A0=9C=20?= =?UTF-8?q?-=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://kimvampa.tistory.com/225 --- .../com/vam/controller/AdminController.java | 37 +++++++++++++++++++ .../maven/com.vam/controller/pom.properties | 2 +- .../com/vam/controller/AdminController.java | 37 +++++++++++++++++++ .../maven/com.vam/controller/pom.properties | 2 +- 4 files changed, 76 insertions(+), 2 deletions(-) diff --git a/VamPa/src/main/java/com/vam/controller/AdminController.java b/VamPa/src/main/java/com/vam/controller/AdminController.java index 3e786c5..fc41500 100644 --- a/VamPa/src/main/java/com/vam/controller/AdminController.java +++ b/VamPa/src/main/java/com/vam/controller/AdminController.java @@ -3,6 +3,7 @@ package com.vam.controller; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; +import java.net.URLDecoder; import java.nio.file.Files; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -405,4 +406,40 @@ public class AdminController { return result; } + /* 이미지 파일 삭제 */ + @PostMapping("/deleteFile") + public ResponseEntity deleteFile(String fileName){ + + logger.info("deleteFile........" + fileName); + + File file = null; + + try { + /* 썸네일 파일 삭제 */ + file = new File("c:\\upload\\" + URLDecoder.decode(fileName, "UTF-8")); + + file.delete(); + + /* 원본 파일 삭제 */ + String originFileName = file.getAbsolutePath().replace("s_", ""); + + logger.info("originFileName : " + originFileName); + + file = new File(originFileName); + + file.delete(); + + + } catch(Exception e) { + + e.printStackTrace(); + + return new ResponseEntity("fail", HttpStatus.NOT_IMPLEMENTED); + + } // catch + + return new ResponseEntity("success", HttpStatus.OK); + + } + } diff --git a/VamPa/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties b/VamPa/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties index 868baae..d7193cf 100644 --- a/VamPa/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties +++ b/VamPa/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties @@ -1,5 +1,5 @@ #Generated by Maven Integration for Eclipse -#Thu May 20 17:06:13 KST 2021 +#Wed Jun 02 01:27:11 KST 2021 m2e.projectLocation=C\:\\Users\\sjinj\\git\\Blog_Project2\\VamPa m2e.projectName=VamPa groupId=com.vam diff --git a/VamPa_MySQL/src/main/java/com/vam/controller/AdminController.java b/VamPa_MySQL/src/main/java/com/vam/controller/AdminController.java index 207f32c..43b0f62 100644 --- a/VamPa_MySQL/src/main/java/com/vam/controller/AdminController.java +++ b/VamPa_MySQL/src/main/java/com/vam/controller/AdminController.java @@ -3,6 +3,7 @@ package com.vam.controller; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; +import java.net.URLDecoder; import java.nio.file.Files; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -407,4 +408,40 @@ public class AdminController { return result; } + /* 이미지 파일 삭제 */ + @PostMapping("/deleteFile") + public ResponseEntity deleteFile(String fileName){ + + logger.info("deleteFile........" + fileName); + + File file = null; + + try { + /* 썸네일 파일 삭제 */ + file = new File("c:\\upload\\" + URLDecoder.decode(fileName, "UTF-8")); + + file.delete(); + + /* 원본 파일 삭제 */ + String originFileName = file.getAbsolutePath().replace("s_", ""); + + logger.info("originFileName : " + originFileName); + + file = new File(originFileName); + + file.delete(); + + + } catch(Exception e) { + + e.printStackTrace(); + + return new ResponseEntity("fail", HttpStatus.NOT_IMPLEMENTED); + + } // catch + + return new ResponseEntity("success", HttpStatus.OK); + + } + } diff --git a/VamPa_MySQL/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties b/VamPa_MySQL/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties index b0bfc98..a9b4394 100644 --- a/VamPa_MySQL/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties +++ b/VamPa_MySQL/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties @@ -1,5 +1,5 @@ #Generated by Maven Integration for Eclipse -#Thu May 20 17:06:13 KST 2021 +#Wed Jun 02 01:27:11 KST 2021 m2e.projectLocation=C\:\\Users\\sjinj\\git\\Blog_Project2\\VamPa_MySQL m2e.projectName=VamPa_MySQL groupId=com.vam