[Spring][쇼핑몰 프로젝트][26] 업로드 이미지 삭제 - 1

https://kimvampa.tistory.com/225
This commit is contained in:
SeoJin Kim
2021-06-02 01:29:10 +09:00
parent ab1bbf53a6
commit b834a3ca40
4 changed files with 76 additions and 2 deletions

View File

@@ -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<String> 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<String>("fail", HttpStatus.NOT_IMPLEMENTED);
} // catch
return new ResponseEntity<String>("success", HttpStatus.OK);
}
}

View File

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

View File

@@ -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<String> 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<String>("fail", HttpStatus.NOT_IMPLEMENTED);
} // catch
return new ResponseEntity<String>("success", HttpStatus.OK);
}
}

View File

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