Skip to content

Commit

Permalink
refac: S3이미지 코드 리팩토링
Browse files Browse the repository at this point in the history
  • Loading branch information
Train0303 committed Nov 11, 2023
1 parent cd4f035 commit 7d31964
Showing 1 changed file with 2 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.amazonaws.services.s3.model.ObjectMetadata;
import com.amazonaws.services.s3.model.PutObjectRequest;
import com.kakao.linknamu.core.exception.Exception400;
import com.kakao.linknamu.thirdparty.utils.JsoupUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
Expand All @@ -28,7 +27,6 @@ public class S3ImageClient {
private final JsoupUtils jsoupUtils;

public String base64ImageToS3(String base64Data) {

try {
byte[] byteImage = java.util.Base64.getDecoder().decode(base64Data);

Expand All @@ -45,7 +43,7 @@ public String base64ImageToS3(String base64Data) {
return amazonS3Client.getUrl(bucket, fileName).toString();
} catch (IllegalArgumentException e) {
//base64로 인코딩된 이미지파일이 아닐경우, 이미지Url인지 확인
if (getValidImageUrl(base64Data)) {
if (isValidImageUrl(base64Data)) {
return base64Data;
}
throw new Exception400(UtilExceptionStatus.NOT_BASE64_DATA);
Expand All @@ -61,12 +59,9 @@ public String base64ImageToS3(String base64Data, String bookmarkLink) {
}

private ByteArrayInputStream getValidImageInputStream(byte[] byteImage) {


ByteArrayInputStream imageInputStream = new ByteArrayInputStream(byteImage);

try {

BufferedImage image = ImageIO.read(imageInputStream);

// image인지 체크하는 로직
Expand All @@ -82,11 +77,8 @@ private ByteArrayInputStream getValidImageInputStream(byte[] byteImage) {
}


private Boolean getValidImageUrl(String imgUrlString) {


private Boolean isValidImageUrl(String imgUrlString) {
try {

URL imgUrl = new URL(imgUrlString);
BufferedImage image = ImageIO.read(imgUrl);

Expand Down

0 comments on commit 7d31964

Please sign in to comment.