파일 Upload 크기 제한 설정

2019. 6. 16. 14:55plming/Java-Spring Boot

- 기본은 1MB

- multipart/form-data 로 받을 수 있는 것은 10MB

 

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

 

MultipartProperties (Spring Boot Docs 2.0.10.BUILD-SNAPSHOT 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

 

- src/main/resources/application.properties 에 아래 설정들로 조정할 수 있다.

- 기본

 spring.servlet.multipart.max-file-size=128KB
 spring.servlet.multipart.max-request-size=128KB

- multipart/form-data 로 받는

 spring.http.multipart.max-file-size=128KB
 spring.http.multipart.max-request-size=128KB

https://spring.io/guides/gs/uploading-files/

#Tuning file upload limits

 

하지만, Rest API로 만들고

Swagger로 Test하려할 때 multipart/form-data가 제대로 안되는 것 같을 때

기본 설정을 추가해주면 Swagger에서도 Test가 잘 된다.

 

 

+ Swagger Tip 하나 더

@RequestBody가 아닌

@RequestPart xxxDto 로 정의한 경우

Swagger에서는 1개의 InputBox로만 표시되는데...

 

xxxDto의 모든 항목을 입력해야 할 때는

아래처럼 여러개의 값을 갖는 json 형태로 입력하면 Test할 수 있다.

 { "aaa": "111", "bbb": "222" }