파일 업로드 설정
환경설정
<!-- 파일을 처리하기 위한 라이브러리 의존 관계 정의 -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<!-- 파일업로드를 처리하기 위한 라이브러리 의존 관계 정의 -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.2</version>
</dependency>
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
<!--
web.xml의 설정은 WAS(tomcat) 자체 설정일 뿐입니다.
multipart-config : 메모리 사이즈, 업로드 파일 저장 위치, 최대 크기 설정
- location : 저장될 디렉토리(필수)
- max-file-size : 업로드 파일 최대 크기(기본값 : -1L, 제한이 없다)
- max-request-size : 한번 요청 시 업로드 파일 최대 크기
- file-size-threshold : 설정 크리가 넘는 경우 임시 디렉토리에 저장(기본값:0, 설정하지 않는 한 무조건 저장)
web.xml에서 설정하지 않을때는 @MultipartConfig 어노테이션으로도 설정이 가능하다.
- 요청을 받는 컨트롤러에 설정이 가능하다. (메소드 라인이 아니라 컨트롤러인 클래스 라인에 설정한다)
- @MultipartConfig(
location = "D:\\\\uoplad",
maxFileSize = "24681474"
maxRequestSize = "485647218",
fileSizeThreshold = "153812744"
)
임시파일이 저장되는 경로는 아래와 같다.
- C:\\Users\\sem\\AppData\\Local\\Temp
-->
<multipart-config>
<location>C:\\\\upload</location>
<max-file-size>20971520</max-file-size>
<max-request-size>41943040</max-request-size>
<file-size-threshold>20971520</file-size-threshold>
</multipart-config>
</servlet>