Skip to content

Commit

Permalink
Merge pull request #65 from hyun357123/main
Browse files Browse the repository at this point in the history
update for fileupload
  • Loading branch information
hyun357123 authored Sep 30, 2024
2 parents d7d75c9 + 387de52 commit cac4e71
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/main/java/kr/co/mcmp/util/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.stream.Stream;

import org.apache.commons.lang3.StringUtils;
import org.springframework.core.io.ClassPathResource;
import org.springframework.web.multipart.MultipartFile;

import lombok.extern.slf4j.Slf4j;
Expand All @@ -24,8 +25,8 @@
public class FileUtils {


private static String projectRoot = System.getProperty("user.dir");
private static String ICON_UPLOAD_DIR = Paths.get(projectRoot, "src", "main", "resources", "static", "images").toString();
// private static String projectRoot = System.getProperty("user.dir");
// private static String ICON_UPLOAD_DIR = Paths.get(projectRoot, "src", "main", "resources", "static", "images").toString();

public static String readLine(InputStream is) throws IOException {
StringBuffer out = new StringBuffer();
Expand Down Expand Up @@ -103,9 +104,6 @@ public static File createDirectory(File directory) {
return directory;
}




public static String uploadIcon(MultipartFile iconFile) throws IOException {
/* 파일 확장자 검사 */
String originalFilename = iconFile.getOriginalFilename();
Expand All @@ -123,6 +121,8 @@ public static String uploadIcon(MultipartFile iconFile) throws IOException {
}
String uniqueFilename = UUID.randomUUID().toString() + fileExtension;
/* 업로드할 전체 경로 생성 */
ClassPathResource resource = new ClassPathResource("static/images");
String ICON_UPLOAD_DIR = resource.getFile().getAbsolutePath();
Path uploadPath = Paths.get(ICON_UPLOAD_DIR).toAbsolutePath().normalize();
File destFile = new File(uploadPath.toFile(), uniqueFilename);
/* 디렉토리가 존재하지 않으면 생성 */
Expand All @@ -133,6 +133,7 @@ public static String uploadIcon(MultipartFile iconFile) throws IOException {
// 저장된 파일의 상대 경로 반환
return "/images/" + uniqueFilename;
}

public static void copy(File sourceLocation, File targetLocation) throws IOException {
if (sourceLocation.isDirectory()) {
if (!targetLocation.isDirectory()) {
Expand Down

0 comments on commit cac4e71

Please sign in to comment.