diff --git a/src/main/java/es/princip/getp/api/handler/MaxUploadSizeExceededExceptionHandler.java b/src/main/java/es/princip/getp/api/handler/MaxUploadSizeExceededExceptionHandler.java new file mode 100644 index 00000000..157607a8 --- /dev/null +++ b/src/main/java/es/princip/getp/api/handler/MaxUploadSizeExceededExceptionHandler.java @@ -0,0 +1,28 @@ +package es.princip.getp.api.handler; + +import es.princip.getp.api.support.dto.ApiErrorResponse; +import es.princip.getp.api.support.dto.ApiErrorResponse.ApiErrorResult; +import es.princip.getp.domain.support.ErrorDescription; +import lombok.extern.slf4j.Slf4j; +import org.springframework.core.annotation.Order; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; +import org.springframework.web.multipart.MaxUploadSizeExceededException; + +@Slf4j +@Order(1) +@RestControllerAdvice +public class MaxUploadSizeExceededExceptionHandler { + + @ExceptionHandler(MaxUploadSizeExceededException.class) + public ResponseEntity handle(final MaxUploadSizeExceededException exception) { + log.debug(exception.getMessage(), exception); + final ErrorDescription description = ErrorDescription.of( + "MAX_UPLOAD_SIZE_EXCEEDED", + "최대 허용 파일 크기를 초과했습니다. " + ); + return ApiErrorResponse.error(HttpStatus.PAYLOAD_TOO_LARGE, description); + } +} \ No newline at end of file diff --git a/src/main/java/es/princip/getp/application/storage/FileLog.java b/src/main/java/es/princip/getp/application/storage/FileLog.java index b5d375b2..adee4ae8 100644 --- a/src/main/java/es/princip/getp/application/storage/FileLog.java +++ b/src/main/java/es/princip/getp/application/storage/FileLog.java @@ -46,7 +46,7 @@ public static FileLog of(final MemberId memberId, final MultipartFile file) { } public Path getPath() { - return Paths.get(String.valueOf(memberId)) + return Paths.get(String.valueOf(memberId.getValue())) .resolve(FILE_PREFIX) .resolve(String.valueOf(id)) .resolve(filename); diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 85fa0011..58e06735 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -4,6 +4,10 @@ server: context-path: ${BASE_PATH} spring: + servlet: + multipart: + max-file-size: 5MB + storage: local: path: ${STORAGE_PATH} diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml index 618fe506..e580ef73 100644 --- a/src/main/resources/application-local.yml +++ b/src/main/resources/application-local.yml @@ -4,6 +4,10 @@ server: context-path: ${BASE_PATH} spring: + servlet: + multipart: + max-file-size: 5MB + storage: local: path: ${STORAGE_PATH}