Skip to content

Commit

Permalink
refactor: 호환 가능 확장자 파일 추가 및 파일 최대 용량 제한 (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ho-Tea authored Jan 23, 2025
1 parent 6db52b2 commit e540ee3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
import org.springframework.web.multipart.MaxUploadSizeExceededException;
import org.springframework.web.servlet.resource.NoResourceFoundException;
import be.dash.dashserver.api.exception.DashApiException;
import be.dash.dashserver.api.exception.ErrorMessage;
Expand All @@ -18,6 +19,7 @@
import be.dash.dashserver.core.exception.NotFoundException;
import be.dash.dashserver.core.log.LogForm;
import lombok.extern.slf4j.Slf4j;
import software.amazon.awssdk.services.s3.model.S3Exception;

@Slf4j
@RestControllerAdvice
Expand Down Expand Up @@ -84,6 +86,18 @@ public ResponseEntity<ErrorMessage> handleNotFoundException(NotFoundException e)
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new ErrorMessage(e.getMessage()));
}

@ExceptionHandler(MaxUploadSizeExceededException.class)
public ResponseEntity<ErrorMessage> handleMaxUploadSizeExceededException(MaxUploadSizeExceededException e) {
log.warn("handleMaxUploadSizeExceededException in GlobalExceptionHandler throw {} : {}", e.getClass(), e.getMessage());
return ResponseEntity.status(HttpStatus.PAYLOAD_TOO_LARGE).body(new ErrorMessage(e.getMessage()));
}

@ExceptionHandler(S3Exception.class)
public ResponseEntity<ErrorMessage> handleS3Exception(S3Exception e) {
log.warn("handleS3Exception in GlobalExceptionHandler throw {} : {}", e.getClass(), e.getMessage());
return ResponseEntity.badRequest().body(new ErrorMessage(e.getMessage()));
}

@ExceptionHandler(DashApiException.class)
public ResponseEntity<ErrorMessage> handleDashApiException(DashApiException e) {
log.warn("handleDashApiException in GlobalExceptionHandler throw {} : {}", e.getClass(), e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
public class S3ImageUploader implements ImageUploader {
private final S3Properties s3Properties;
private final S3Config s3Config;
private static final List<String> IMAGE_EXTENSIONS = Arrays.asList("image/jpeg", "image/png", "image/jpg", "image/webp");
private static final List<String> IMAGE_EXTENSIONS = Arrays.asList("image/jpeg", "image/png", "image/jpg", "image/webp", "image/heic", "image/heif");

@Override
public String uploadImage(MultipartFile image) throws IOException {
Expand Down Expand Up @@ -49,7 +49,7 @@ private String generateImageFileName() {
private void validateExtension(MultipartFile image) {
String contentType = image.getContentType();
if (!IMAGE_EXTENSIONS.contains(contentType)) {
throw new BadRequestException("이미지 확장자는 jpg, png, webp만 가능합니다.");
throw new BadRequestException("이미지 확장자는 jpg, png, webp, heic, heif만 가능합니다.");
}
}
}

0 comments on commit e540ee3

Please sign in to comment.