diff --git a/src/main/java/com/stumeet/server/file/adapter/out/S3ImageStorageAdapter.java b/src/main/java/com/stumeet/server/file/adapter/out/S3ImageStorageAdapter.java index baa82065..41ed37d5 100644 --- a/src/main/java/com/stumeet/server/file/adapter/out/S3ImageStorageAdapter.java +++ b/src/main/java/com/stumeet/server/file/adapter/out/S3ImageStorageAdapter.java @@ -11,9 +11,9 @@ import com.stumeet.server.common.exception.model.NotImplementedException; import com.stumeet.server.common.response.ErrorCode; import com.stumeet.server.common.util.FileUtil; +import com.stumeet.server.common.util.FileValidator; import com.stumeet.server.file.application.port.out.FileCommandPort; import com.stumeet.server.file.application.port.out.FileUrl; -import com.stumeet.server.file.domain.ImageFile; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -36,11 +36,11 @@ public class S3ImageStorageAdapter implements FileCommandPort { @Override public FileUrl uploadImageFile(MultipartFile file, String directoryPath) { - ImageFile imageFile = new ImageFile(file); - String key = FileUtil.generateKey(directoryPath, imageFile.getName()); + FileValidator.validateImageFile(file); + String key = FileUtil.generateKey(directoryPath, file.getOriginalFilename()); PutObjectRequest objectRequest = PutObjectRequest.builder() - .contentType(imageFile.getContentType()) + .contentType(file.getContentType()) .bucket(bucket) .key(key) .build(); diff --git a/src/main/java/com/stumeet/server/file/domain/ImageFile.java b/src/main/java/com/stumeet/server/file/domain/ImageFile.java deleted file mode 100644 index d605032e..00000000 --- a/src/main/java/com/stumeet/server/file/domain/ImageFile.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.stumeet.server.file.domain; - -import org.springframework.web.multipart.MultipartFile; - -import com.stumeet.server.common.exception.model.BusinessException; -import com.stumeet.server.common.response.ErrorCode; -import com.stumeet.server.common.util.FileUtil; - -import lombok.Getter; - -@Getter -public class ImageFile { - - private final MultipartFile file; - - private final String name; - - private final String contentType; - - private final String extension; - - public ImageFile(MultipartFile file) { - this.file = file; - this.name = file.getOriginalFilename(); - this.contentType = file.getContentType(); - this.extension = FileUtil.extractExtension(name); - validate(); - } - - private void validate() { - if (contentType == null || extension == null) { - throw new BusinessException(ErrorCode.INVALID_IMAGE_FILE_EXCEPTION); - } - - if (!ImageContentType.isValid(contentType, extension)) { - throw new BusinessException(ErrorCode.INVALID_FILE_EXTENSION_EXCEPTION); - } - } -}