Framework/Spring Boot

업로드 파일 사이즈

잔망루피 2022. 8. 16. 18:58
반응형
org.apache.tomcat.util.http.fileupload.impl.FileSizeLimitExceededException: The field file exceeds its maximum permitted size of 1048576 bytes.

이미지 파일 하나 업로드하니까 다음과 같은 에러 발생

기본값이 1048576 bytes

 

 

🌿 해결

spring.servlet.multipart.max-file-size=5MB
spring.servlet.multipart.max-request-size=10MB

build.gradle에 추가하자.

max-file-size는 허용 가능한 최대 바이트 사이즈다. 업로드한 파일 중에서 max-file-size를 초과하는 파일이 있다면, IllegalStateException 발생. 기본 값은 1MB

max-request-size는 multipart/form-data 요청에서 허용되는 최대 바이트 사이즈다. 총 업로드 파일의 사이즈가 max-request-size를 초과하면 예외를 발생. 기본 값은 10MB

 

var maxSize=5 * 1024 * 1024;
$(document).ready(function () {
    $('.summernote').summernote({
        placeholder: '내용을 입력해주세요.',
        height:500,
        //콜백 함수
        callbacks : {
           onImageUpload : function(files, editor, welEditable) {
                // 파일 업로드(다중업로드를 위해 반복문 사용)
                for (var i = files.length - 1; i >= 0; i--) {
                    if(files[i].size > maxSize){
                        alert("첨부파일 사이즈는 5MB 이내로 등록 가능합니다.");
                        break;
                    }
                    uploadSummernoteImageFile(files[i], this);
              }
           }
        }
    });
    $('.note-resizebar').css('display', 'none');
});

프런트엔드에서 첨부파일의 크기가 maxSize를 초과하면 파일 업로드를 중지한다.

alert로 알림창을 띄운다.

해당 파일은 업로드에 실패해서 클라이언트에게도 보이지 않는다.

 

 

참고 👇

https://stackoverflow.com/questions/37540028/how-to-set-the-max-size-of-upload-file

 

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

 

https://hhyemi.github.io/2020/11/05/11051627.html

 

JavaScript - 파일 용량 제한 - CODE:H

파일 용량 제한 자바스크립트단에서 파일 업로드 시 용량을 제한해보자. html javascript $("input[name=IMG_IMG]").off().on("change", function(){ if (this.files && this.files[0]) { var maxSize = 5 * 1024 * 1024; var fileSize = this.f

hhyemi.github.io

 

https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/autoconfigure/web/servlet/MultipartProperties.html

 

MultipartProperties (Spring Boot 2.7.2 API)

Properties to be used in configuring a MultipartConfigElement. location specifies the directory where uploaded files will be stored. When not specified, a temporary directory will be used. max-file-size specifies the maximum size permitted for uploaded fil

docs.spring.io

 

반응형