Notice
Recent Posts
Recent Comments
Link
개발 무지렁이
[Spring Boot] 업로드한 프로필 이미지 저장과 모듈화 본문
saveProfileImg(profileImg)
[MemberService.java]
private String saveProfileImg(MultipartFile profileImg) {
if ( profileImg == null || profileImg.isEmpty() ) {
return null;
}
String profileImgDirName = getCurrentProfileImgDirName();
String ext = Util.file.getExt(profileImg.getOriginalFilename());
String fileName = UUID.randomUUID() + "." + ext;
String profileImgDirPath = genFileDirPath + "/" + profileImgDirName;
String profileImgFilePath = profileImgDirPath + "/" + fileName;
new File(profileImgDirPath).mkdirs();
try {
profileImg.transferTo(new File(profileImgFilePath));
} catch (IOException e) {
throw new RuntimeException(e);
}
return profileImgDirName + "/" + fileName;
}
'Backend > 스프링부트' 카테고리의 다른 글
[Spring Boot] 때에 따라 업로드 개수가 다를 경우, MultipartRequest (0) | 2022.12.26 |
---|---|
[Spring Boot] 프로필 이미지 업데이트와 캐시 (0) | 2022.12.25 |
[Spring Boot] 로깅 기능 라이브러리 Log4j와 properties 파일: 로그 설정정보 세팅 및 @Slf4j (0) | 2022.12.24 |
[Spring Boot] OAuth2와 카카오 로그인을 위한 의존성 추가 및 설정작업 (0) | 2022.12.21 |
[Spring Boot] 브라우저 안의 웹캐시 사용하기 (0) | 2022.12.21 |
Comments