MultipartFile 인터페이스


스프링에서 파일 업로드 절차

1. 라이브러리 구축 및 multipartResolver 등록

  **1-1 라이브러리 구축 (pom.xml)**

1-2 multipartResolver 등록 (dispatcher-survlet.xml)

<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
	<property name="maxUploadSize" value="10485760"></property>
</bean>

2. MultipartFile 받아오기 (방법 3)

3. 복사하기 (메서드로 만들기)

try {
	// 원본 
	byte bytes[] = upload.getBytes();
	
	// 빈 용지
	File f = new File("c:/student_java/upload/"+upload.getOriginalFilename());
	
	// 복사기
	FileOutputStream fos = new FileOutputStream(f);
	
	// 버튼눌러서 복사
	fos.write(bytes);
	
	// 복사 끝나면 종료
	fos.close();
}catch(IOException e){
	e.printStackTrace();
}