-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MATE-132 : [FEAT] 썸네일 이미지 생성 및 저장, 삭제 기능 구현 (#123)
* MATE-132 : [FEAT] 썸네일레이터 의존성 추가 * MATE-132 : [FEAT] 썸네일 이미지 생성 및 저장, 삭제 기능 구현 * MATE-132 : [FEAT] 굿즈거래 게시물 썸네일 이미지 업로드 로직 추가 * MATE-132 : [FEAT] 이미지 Url 반환 기능 구현 및 File 관련 Util 클래스 생성 * MATE-132 : [REFACTOR] 이미지 Url 반환 로직 변경에 따른 DTO 클래스 리팩토링 * MATE-132 : [TEST] 이미지 업로드 및 Url 반환 로직 변경에 따른 테스트 코드 수정 * MATE-132 : [REFACTOR] 회원 및 메이트 도메인 썸네일 로직 추가 * MATE-132 : [TEST] 회원 및 메이트 테스트 코드 수정 * MATE-132 : [REFACTOR] 회원 및 메이트 기본 이미지 생성 로직 수정 * MATE-132 : [TEST] ProfileServiceTest 테스트 코드 수정
- Loading branch information
Showing
29 changed files
with
257 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.example.mate.domain.file; | ||
|
||
import java.util.UUID; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
@Component | ||
public class FileUtils { | ||
|
||
private static final String FILE_NAME_REGEX = "[^a-zA-Z0-9.\\-_]"; | ||
private static final String FILE_NAME_REPLACEMENT = "_"; | ||
private static final String THUMBNAIL_PREFIX = "t_"; | ||
|
||
private static String AWS_BUCKET_URL; | ||
|
||
@Value("${cloud.aws.s3.bucket}") | ||
public void setAwsBucketUrl(String bucket) { | ||
AWS_BUCKET_URL = "https://" + bucket + ".s3.ap-northeast-2.amazonaws.com/"; | ||
} | ||
|
||
public static String getImageUrl(String fileName) { | ||
return AWS_BUCKET_URL + fileName; | ||
} | ||
|
||
public static String getThumbnailImageUrl(String fileName) { | ||
return AWS_BUCKET_URL + THUMBNAIL_PREFIX + fileName; | ||
} | ||
|
||
/** | ||
* 파일명에서 허용되지 않는 문자를 제거하고, UUID 를 추가한 새로운 파일명을 생성 | ||
* | ||
* @param file 업로드할 파일 | ||
* @return UUID 를 포함한 새로운 파일명 | ||
*/ | ||
public static String getFileName(MultipartFile file) { | ||
String uuid = UUID.randomUUID().toString(); | ||
return uuid + FILE_NAME_REPLACEMENT + cleanFileName(file.getOriginalFilename()); | ||
} | ||
|
||
/** | ||
* 파일 이름에서 허용되지 않는 문자를 대체 문자로 변경합니다. | ||
* | ||
* @param fileName 원본 파일명 | ||
* @return 대체된 파일명 | ||
*/ | ||
private static String cleanFileName(String fileName) { | ||
return fileName.replaceAll(FILE_NAME_REGEX, FILE_NAME_REPLACEMENT); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.