개발 환경
- Build : Gradle
- SpringBoot : 2.7.5
- Java : 11
- OS : Mac
발생
포스트맨으로 form-data 이미지 파일을 POST 요청을 보냈을 때 다음과 같은 에러가 발생했다.
org.springframework.web.multipart.MaxUploadSizeExceededException: Maximum upload size exceeded; nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.impl.FileSizeLimitExceededException: The field image exceeds its maximum permitted size of 1048576 bytes.
원인
에러 메세지에서도 알 수 있듯이 스프링에서 파일 업로드는 1MB로 기본 설정이 되어 있는 듯 하다.
따라서 1MB를 초과하는 파일을 받기 위해서는 따로 설정을 해야 한다고 한다.
해결
max-file-size : 파일 하나당 크기
max-request-size : 요청할 때 파일의 총 크기
방법 1. Spring Boot 2.x.x
# application.properties
spring.servlet.multipart.max-file-size= 10MB
spring.servlet.multipart.max-request-size= 10MB
# application.yml
spring:
servlet:
multipart:
max-file-size: 10MB
max-request-size: 10MB
방법 2. Spring Boot 1.4.x ~ 1.5.x
# application.properties
spring.http.multipart.max-file-size= 10MB
spring.http.multipart.max-request-size= 10MB
# application.yml
spring:
http:
multipart:
max-file-size: 10MB
max-request-size: 10MB
방법 3. Spring Boot x.x.x ~ 1.3.x
# application.properties
multipart.max-file-size= 10MB
multipart.max-request-size= 10MB
# application.yml
multipart:
max-file-size: 10MB
max-request-size: 10MB
테스트
Reference
https://server0.tistory.com/41
Spring Boot, 파일 업로드 용량 설정
FileUploadBase$SizeLimitExceededException Spring Boot 에서 파일 업로드를 하다가 오류가 나서 콘솔을 보니 용량 제한이 있었다. 프로필에서 maxFileSize를 설정해주면 되는데, 주의할 점은 maxRequestSize도 설정이
server0.tistory.com
How to set the max size of upload file
I'm developing application based on Spring Boot and AngularJS using JHipster. My question is how to set max size of uploading files? If I'm trying to upload to big file I'm getting this informatio...
stackoverflow.com
'SpringBoot' 카테고리의 다른 글
[SpringBoot] AWS S3 파일(이미지) 업로드 및 삭제하기 구현 (0) | 2022.11.28 |
---|---|
[SpringBoot] MockMvc - multipart() POST외 다른 HTTPMethod 사용하기 (0) | 2022.11.26 |
[TroubleShooting] SpringBoot Controller Test - MockMvc 302 Found, 403 Forbidden (0) | 2022.11.24 |
[SpringDataJPA] 쿼리메서드 참조 객체의 필드 사용 (0) | 2022.11.17 |
[에러해결] HttpMediaTypeNotAcceptableException: Could not find acceptable representation (0) | 2022.09.04 |