diff --git a/src/main/kotlin/gdsc/plantory/common/exception/CommonExceptionHandler.kt b/src/main/kotlin/gdsc/plantory/common/exception/CommonExceptionHandler.kt index 0063aad..93de7d0 100644 --- a/src/main/kotlin/gdsc/plantory/common/exception/CommonExceptionHandler.kt +++ b/src/main/kotlin/gdsc/plantory/common/exception/CommonExceptionHandler.kt @@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory 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 @RestControllerAdvice class CommonExceptionHandler { @@ -27,4 +28,9 @@ class CommonExceptionHandler { return ResponseEntity.internalServerError().body(ErrorResponse("서버 에러가 발생했습니다. 관리자에게 문의해주세요.")) } + + @ExceptionHandler + fun handleMaxSizeException(ex: MaxUploadSizeExceededException): ResponseEntity { + return ResponseEntity.badRequest().body(ErrorResponse("파일의 최대 사이즈를 확인해주세요.")) + } } diff --git a/src/main/kotlin/gdsc/plantory/common/support/photo/PhotoLocalManager.kt b/src/main/kotlin/gdsc/plantory/common/support/photo/PhotoLocalManager.kt index 854d51c..286b17f 100644 --- a/src/main/kotlin/gdsc/plantory/common/support/photo/PhotoLocalManager.kt +++ b/src/main/kotlin/gdsc/plantory/common/support/photo/PhotoLocalManager.kt @@ -58,7 +58,7 @@ class PhotoLocalManager( private fun uploadFileInLocal(multipartFile: MultipartFile, uploadPath: File) { try { - multipartFile.transferTo(uploadPath) + multipartFile.transferTo(uploadPath.toPath()) } catch (e: IOException) { throw IllegalStateException("파일 변환이 실패했습니다.") } diff --git a/src/main/kotlin/gdsc/plantory/plant/presentation/dto/CompanionPlantCreateRequest.kt b/src/main/kotlin/gdsc/plantory/plant/presentation/dto/CompanionPlantCreateRequest.kt index c4995f1..ecb29cc 100644 --- a/src/main/kotlin/gdsc/plantory/plant/presentation/dto/CompanionPlantCreateRequest.kt +++ b/src/main/kotlin/gdsc/plantory/plant/presentation/dto/CompanionPlantCreateRequest.kt @@ -18,8 +18,10 @@ data class CompanionPlantCreateRequest( @DateTimeFormat(pattern = "yyyy-MM-dd") val lastWaterDate: LocalDate, ) { fun toEntity(imagePath: String, memberId: Long, waterCycle: Int): CompanionPlant { + // TODO : Cloud 환경으로 이전 후 제거, 로컬 사진 저장 테스트 용도 + val baseUrl: String = "https://nongsaro.go.kr/" return CompanionPlant( - _imageUrl = imagePath, + _imageUrl = baseUrl + imagePath, _shortDescription = this.shortDescription, _nickname = this.nickname, nextWaterDate = this.lastWaterDate.plusDays(waterCycle.toLong()), @@ -29,4 +31,4 @@ data class CompanionPlantCreateRequest( memberId = memberId, ) } -} \ No newline at end of file +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 4dfb374..1d46cf0 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -15,6 +15,10 @@ spring: username: ${DB_USER} password: ${DB_PASSWORD} driver-class-name: com.mysql.cj.jdbc.Driver + servlet: + multipart: + max-file-size: 20MB + max-request-size: 25MB local: image: @@ -26,5 +30,5 @@ companionPlant: fcm: key: - path: src/main/resources/config/google-services.json + path: config/google-services.json scope: prod diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml index 63c6397..0665b37 100644 --- a/src/test/resources/application.yml +++ b/src/test/resources/application.yml @@ -14,6 +14,10 @@ spring: username: plantory password: plantory1234 driver-class-name: org.testcontainers.jdbc.ContainerDatabaseDriver + servlet: + multipart: + max-file-size: 20MB + max-request-size: 25MB local: image: