HomeAboutMeBlogGuest
© 2025 Sejin Cha. All rights reserved.
Built with Next.js, deployed on Vercel
🧚
[1기]최종 프로젝트 데브코스
/
👼
[팀2] 극락이들
/
📰
[극락이들] 3주차 프로젝트 공유사항
/
‼️
api/v1/images Error 413 코드 관련
‼️

api/v1/images Error 413 코드 관련

생성자
우선순위
2순위
태그
Backend
💚해결 완료
💚해결 완료
조수연
조수연
최민석
김동건
남명훈
남명훈
이소진
황일용
황일용
완료
Yes
🤔 발생 상황 👀 원인 파악(예상)✔ 해결 과정 ✨ Reference

 
 

🤔 발생 상황


  • [오류 이미지 및 코드 캡처]
notion image

👀 원인 파악(예상)


  • 1MB 이상의 파일 게시 시 발생하게 된 오류
  • 프론트에서는 Validation 처리를 해야 할 듯 합니다 😂

✔ 해결 과정


여러분들께서 감사하게도 에러를 찾아주시고 관련 레퍼런스를 참고해주신점을 바탕으로 해결을 할 수 있었습니다.
 
위의 에러는 악의적인 사용을 방지하기위해 한 번의 파일전송 용량을 default 1MB로 설정되어 있어서 용량이 초과된 파일을 전송하는 경우 발생하는 예외입니다.
 
따라서 NGINX와 TOMCAT에서 파일 업로드 요청 용량 허용 범위를 늘려주는 방법을 해결하였습니다.
 
  • nginx에서 client_max_body_size 를 최대 10M까지 설정하여 파일을 받도록 허용합니다.
    • http { ## # Basic Settings ## ... client_max_body_size 10M;
 
  • nginx에서 해결해주니 이번에는 tomcat에서 오류를 뱉네용!
    • 2021-12-16 04:17:00.688 ERROR 1 --- [nio-8080-exec-7] o.a.c.c.C.[.[.[.[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.web.multipart.MaxUploadSizeExceededException: Maximum upload size exceeded; nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field image exceeds its maximum permitted size of 1048576 bytes.] with root cause org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field image exceeds its maximum permitted size of 1048576 bytes. at org.apache.tomcat.util.http.fileupload.FileUploadBase$FileItemIteratorImpl$FileItemStreamImpl$1.raiseError(FileUploadBase.java:633) ~[tomcat-embed-core-9.0.29.jar!/:9.0.29] at org.apache.tomcat.util.http.fileupload.util.LimitedInputStream.checkLimit(LimitedInputStream.java:76) ~[tomcat-embed-core-9.0.29.jar!/:9.0.29] at org.apache.tomcat.util.http.fileupload.util.LimitedInputStream.read(LimitedInputStream.java:135) ~[tomcat-embed-core-9.0.29.jar!/:9.0.29] at java.io.FilterInputStream.read(FilterInputStream.java:107) ~[?:?]
 
  • Spring config 에서 파일용량 허용을 늘려봅시다.
    • spring: servlet: multipart: max-file-size: 10MB max-request-size: 10MB
3MB 이미지 업로드 성공!
{ "message": "IMAGE_UPLOAD_SUCCESS", "serverDateTime": "2021-12-16T04:35:07.300864", "data": { "uploadImageUrl": "https://jungdam-image.s3.ap-northeast-2.amazonaws.com/temp/dd548eee-5d1a-4303-882e-a1bc602a9c44" } }

✨ Reference


  • 해결하기 위한 레퍼런스
    • [nginx] 413 Request Entity Too Large 오류
      by 스뎅(thDeng) on nginx로 reverse proxy 를 사용할 때, 용량이 큰 파일을 업로드하면 413 Request Entity Too Large 라는 메시지를 볼 수 있다. client_max_body_size 설정 때문이고, 너무 큰 사이즈의 request를 보내지 못 하도록 제한을 걸 수 있다. 기본값은 1MB이다. request의 Content-Length 헤더값이 여기 설정된 값을 넘을 수 없다.
      [nginx] 413 Request Entity Too Large 오류
      https://blog.leocat.kr/notes/2020/04/21/nginx-413-request-entity-too-large
      [nginx] 413 Request Entity Too Large 오류
      Spring Boot 파일 업로드 용량제한 설정
      multipart.MaxUploadSizeExceededException: Maximum upload size exceeded; nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field sourceFile exceeds its maximum permitted size of 1048576 bytes. 이는 error log 뜻 그대로 업로드할 수 있는 최대 용량을 넘긴 파일을 업로드하려 할 때 발생하는 에러입니다 이 때, 1048576 bytes는 약 1MB로 용량 설정을 하지 않았을 때의 디폴트 값입니다 해결 방법은 spring boot의 파일 용량 설정값을 변경해주는 것입니다 ※ Spring Boot의 버전에 따라 추가하는 코드에 약간의 차이가 있습니다.
      Spring Boot 파일 업로드 용량제한 설정
      https://artiiicy.tistory.com/8
      Spring Boot 파일 업로드 용량제한 설정