1414import store .lastdance .exception .CustomException ;
1515import store .lastdance .exception .ErrorCode ;
1616import store .lastdance .repository .common .ImageFileRepository ;
17+ import store .lastdance .service .common .FileValidationService ;
1718
1819import java .time .Duration ;
1920import java .util .UUID ;
@@ -26,6 +27,7 @@ public class ImageServiceImpl implements ImageService {
2627 private final ImageFileRepository imageFileRepository ;
2728 private final S3Operations s3Operations ;
2829 private final S3Presigner s3Presigner ;
30+ private final FileValidationService fileValidationService ;
2931
3032 @ Value ("${spring.cloud.aws.s3.bucket}" )
3133 private String bucketName ;
@@ -117,21 +119,23 @@ private void validateImageFile(MultipartFile file, int maxSize) {
117119 throw new CustomException (ErrorCode .FILE_SIZE_EXCEEDED );
118120 }
119121
120- String contentType = file .getContentType ();
121- if (contentType == null || !contentType .startsWith ("image/" )) {
122- throw new CustomException (ErrorCode .INVALID_FILE_TYPE );
123- }
124-
125- String filename = file .getOriginalFilename ();
126- if (filename == null || !isAllowedExtensions (filename )) {
127- throw new CustomException (ErrorCode .INVALID_FILE_EXTENSION );
128- }
129- }
130-
131- private boolean isAllowedExtensions (String filename ) {
132- String extension = getFileExtension (filename ).toLowerCase ();
133- return extension .equals (".jpg" ) || extension .equals (".jpeg" ) ||
134- extension .equals (".png" ) || extension .equals (".gif" );
122+ fileValidationService .validateImageFile (file );
123+
124+ // String contentType = file.getContentType();
125+ // if (contentType == null || !contentType.startsWith("image/")) {
126+ // throw new CustomException(ErrorCode.INVALID_FILE_TYPE);
127+ // }
128+ //
129+ // String filename = file.getOriginalFilename();
130+ // if (filename == null || !isAllowedExtensions(filename)) {
131+ // throw new CustomException(ErrorCode.INVALID_FILE_EXTENSION);
132+ // }
133+ // }
134+ //
135+ // private boolean isAllowedExtensions(String filename) {
136+ // String extension = getFileExtension(filename).toLowerCase();
137+ // return extension.equals(".jpg") || extension.equals(".jpeg") ||
138+ // extension.equals(".png") || extension.equals(".gif");
135139 }
136140
137141}
0 commit comments