This commit is contained in:
dyhj625 2025-01-24 14:45:00 +09:00
commit f2c330577a
3 changed files with 11 additions and 6 deletions

View File

@ -41,6 +41,9 @@ public class WebMvcConfig implements WebMvcConfigurer {
@Value("${filePath.boardfile}")
private String boardFilePath;
@Value("${filePath.profile}")
private String uploadPath;
@Override
public void addInterceptors(InterceptorRegistry registry) {
@ -58,6 +61,9 @@ public class WebMvcConfig implements WebMvcConfigurer {
//게시판 에디터 이미지 업로드 경로
registry.addResourceHandler("/upload/img/board/**")
.addResourceLocations("file:" + boardFilePath);
//프로필 이미지 업로드 경로
registry.addResourceHandler("/upload/img/profile/**")
.addResourceLocations("file:" + uploadPath);
}
// Controller의 파라미터를 처리할 Resolver 등록

View File

@ -38,11 +38,10 @@ public class FileService {
* 파일 업로드
*
* @param file
* @param directory
* @return
* @throws RuntimeException
*/
public String uploadFile(MultipartFile file, String directory) {
public String uploadFile(MultipartFile file) {
try {
// 원본 파일명
String originalFilename = file.getOriginalFilename();
@ -52,7 +51,7 @@ public class FileService {
String newFilename = UUID.randomUUID().toString() + "." + extension;
// 최종 저장 경로 생성 (기본경로 + 하위디렉토리 + 파일명)
Path targetPath = Paths.get(uploadPath, directory, newFilename);
Path targetPath = Paths.get(uploadPath, newFilename);
// 저장될 디렉토리가 없는 경우 생성
Files.createDirectories(targetPath.getParent());
@ -60,7 +59,7 @@ public class FileService {
Files.copy(file.getInputStream(), targetPath, StandardCopyOption.REPLACE_EXISTING);
// 저장된 파일의 상대 경로 반환
return directory + "/" + newFilename;
return newFilename;
} catch (IOException e) {
throw new RuntimeException("파일 업로드 실패: " + e.getMessage());

View File

@ -43,7 +43,7 @@ public class netmemberService {
*/
public int register(MultipartFile memberPrf, MapDto map) {
// 프로필 이미지 저장, 저장된 경로 가져옴
String profilePath = fileService.uploadFile(memberPrf, "profiles");
String profilePath = fileService.uploadFile(memberPrf);
map.put("memberPrf", profilePath);
// 비밀번호 암호화 저장
@ -54,7 +54,7 @@ public class netmemberService {
map.put("memberRol", "ROLE_MEMBER");
map.put("memberPos", 500107);
map.put("memberTkn", "Null");
map.put("memberPrm", "N");
map.put("memberPrm", "Y");
map.put("memberDel", "N");
map.put("memberLea", "N");
map.put("memberRdt", LocalDateTime.now());