๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿ’ปStudy/Spring

POST ์ž…๋ ฅ - ํŒŒ์ผ ์—…๋กœ๋“œ



form ํƒœ๊ทธ์—์„œ ์ธ์ฝ”๋”ฉ ๋ฐฉ์‹์„ ํŠน๋ณ„ํžˆ ์ง€์ •ํ•˜์ง€ ์•Š๋Š”๋‹ค๋ฉด ๊ธฐ๋ณธ์ ์œผ๋กœ POST ๋ฐฉ์‹์œผ๋กœ "uid=newlec&name=dragon"์ฒ˜๋Ÿผ &๋กœ ๊ตฌ๋ถ„๋œ "ํ‚ค=๊ฐ’"์ด ์ „์†ก๋œ๋‹ค. url์— ์‚ฌ์šฉ๋˜๋Š” ์ฟผ๋ฆฌ์ŠคํŠธ๋ง๊ณผ ๊ฐ™์€ ํ˜•์‹์ด๋‹ค. ๋ฌธ์ž์—ด๋งŒ ๋ณด๋‚ผ ๋•Œ๋Š” ์ด๋Ÿฌํ•œ ๋ฐฉ์‹์œผ๋กœ ๋ณด๋‚ด๋„ ๋˜์ง€๋งŒ ๋ฐ”์ด๋„ˆ๋ฆฌ ๊ฐ’์„ ๋ณด๋‚ผ ๋•Œ ๋ฌธ์ œ๊ฐ€ ์ƒ๊ธฐ๋ฏ€๋กœ ํด๋ผ์ด์–ธํŠธ์—์„œ ์ธ์ฝ”๋”ฉ ๋ฐฉ์‹์„ ๋‹ฌ๋ฆฌํ•ด์•ผ ํ•œ๋‹ค. (=>multipart)

 

 

 

 

multipart ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•˜๋ฉด ์œ„ ๊ทธ๋ฆผ์ฒ˜๋Ÿผ ํŒŒํŠธ๋ฅผ ๋‚˜๋ˆ„์–ด์„œ ์ „์†กํ•˜๊ฒŒ ๋œ๋‹ค. (์ฒซ ๋ฒˆ์งธ ํŒŒํŠธ๋Š” uid, ๋‘ ๋ฒˆ์งธ ํŒŒํŠธ๋Š” name, ์„ธ ๋ฒˆ์งธ ํŒŒํŠธ๋Š” file...)

 

ํด๋ผ์ด์–ธํŠธ์—์„œ ๊ฐ’์„ ์ „์†กํ•  ๋•Œ์˜ ๊ธฐ๋ณธ ๋ฐฉ์‹์ด application/x-www-form-urlencoded ์ด๋ผ์„œ multipart ๋ฐฉ์‹์„ ์„ค์ •ํ•ด์•ผ ํ•˜๋Š” ๊ฒƒ์ฒ˜๋Ÿผ, ์„œ๋ฒ„์—์„œ๋„ multipart ๋ฐฉ์‹์„ ๋ฐ›๊ธฐ ์œ„ํ•ด์„œ๋Š” ๋˜ ๋‹ค๋ฅธ ์„ค์ •์ด ํ•„์š”ํ•˜๋‹ค.

 

 

servlet-context.xml

	<!-- ํŒŒ์ผ ์—…๋กœ๋“œ๋ฅผ ์œ„ํ•œ multipart ์„ค์ • -->
	<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
		<!-- setting maximum upload size 300MB(1024-1024*300) -->
		<property name="maxUploadSize" value="314572800"></property>
	</bean>

 

์„œ๋ธ”๋ฆฟ ์„ค์ •์— CommonsMultipartResolver๋ฅผ ์ถ”๊ฐ€ํ•œ๋‹ค.

 

(docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/multipart/commons/CommonsFileUploadSupport.html)

 

 

- setMaxUploadSize : ์ „์ฒด ํŒŒ์ผ ์‚ฌ์ด์ฆˆ์˜ ์ตœ๋Œ€ ์‚ฌ์ด์ฆˆ

- setMaxUploadSizePerFile : ์—…๋กœ๋“œํ•˜๋Š” ํŒŒ์ผ ํ•˜๋‚˜ ๋‹น ์ตœ๋Œ€ ์‚ฌ์ด์ฆˆ

- setDefaultEncoding์€ ํ•˜์ง€ ์•Š์•„๋„ ๋จ. (ํ•„ํ„ฐ๋ฅผ ์‚ฌ์šฉํ•ด ์ธ์ฝ”๋”ฉ์„ ์ง€์ •ํ–ˆ๊ธฐ ๋•Œ๋ฌธ)

 

 

1024byte=1KB ์ด๊ณ  1024byte*1024byte=1MB, ๋”ฐ๋ผ์„œ 1024*1024*300์€ 300MB์ด๋‹ค. 300MB๋ฅผ ์ตœ๋Œ€ ์‚ฌ์ด์ฆˆ๋กœ ํ•˜๊ธฐ ์œ„ํ•ด value์— 314572800์˜ ๊ฐ’์„ ๋„ฃ์—ˆ๋‹ค.

 

 

reg1.html

<form action="reg" method="post" enctype="multipart/form-data">
<!-- ์ดํ•˜ ์ƒ๋žต -->

 

form ํƒœ๊ทธ์— enctype="multipart/form-data" ์„ค์ •์„ ์ถ”๊ฐ€ํ•œ๋‹ค. (๋””ํดํŠธ๋Š” application/x-www-form-urlencoded)

 

 

NoticeController.java

	@RequestMapping("reg")
	@ResponseBody
	public String reg(String title, String content, MultipartFile file, String category, String[] foods, String food) {
		
		String fileName = file.getOriginalFilename();
		long fileSize = file.getSize();
		
		System.out.printf("fileName:%s, fileSize:%d\n", fileName, fileSize);
		
		for(String f : foods) {
			System.out.println(f);
		}
		
		return String.format("title:%s, content:%s<br>category:%s, food:%s", title, content, category, food);
	}

 

MultipartFile ํƒ€์ž…์œผ๋กœ file์„ ๋ฐ›์•„์˜จ๋‹ค.

- getOriginalFilename : ํŒŒ์ผ์˜ ์ €์žฅ๋ช….ํ™•์žฅ์ž (ex. img1.png)

- getSize : ํŒŒ์ผ์˜ ์‚ฌ์ด์ฆˆ (ex. 2881) => ๋ฐ”์ดํŠธ๋ฅผ ์˜๋ฏธ

 

 

pom.xml

	<!-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload -->
	<dependency>
	    <groupId>commons-fileupload</groupId>
	    <artifactId>commons-fileupload</artifactId>
	    <version>1.4</version>
	</dependency>

 

commons-fileupload ๋””ํŽœ๋˜์‹œ๋ฅผ ์ถ”๊ฐ€ํ•œ๋‹ค.

 

 

์‹คํ–‰ํ•˜๊ณ  ๋ทฐ ํŽ˜์ด์ง€์—์„œ ํŒŒ์ผ์„ ์ฒจ๋ถ€ํ•˜์—ฌ submit ํ•˜๋ฉด ํŒŒ์ผ ์ด๋ฆ„๊ณผ ์‚ฌ์ด์ฆˆ๊ฐ€ ์ถœ๋ ฅ๋œ๋‹ค.

 

 

 

* ๋ฌผ๋ฆฌ ๊ฒฝ๋กœ ์–ป๊ธฐ์™€ ํŒŒ์ผ ์ €์žฅํ•˜๊ธฐ

 

 

 

 

์ „๋‹ฌ๋ฐ›์€ ํŒŒ์ผ์„ ๋””๋ ‰ํ† ๋ฆฌ์— ์ €์žฅํ•˜๊ณ ์ž ํ•  ๋•Œ๋Š” ๊ฒฝ๋กœ ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ์ง€์ •ํ•˜๊ณ  ๊ทธ๊ณณ์— ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•˜๋ฉด ๋œ๋‹ค. ํ™ˆ ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ์•Œ์•„๋‚ด์„œ ํ•ด๋‹น ๊ฒฝ๋กœ์— ์ €์žฅํ•ด์•ผ ํ•˜๋Š”๋ฐ, ๊ฐœ๋ฐœํ•  ๋•Œ์˜ ๊ฒฝ๋กœ์™€ ๊ฐœ๋ฐœ ํ›„ ์„œ๋ฒ„ ๋ฐฐํฌํ–ˆ์„ ๋•Œ์˜ ๊ฒฝ๋กœ๊ฐ€ ๋‹ค๋ฅผ ์ˆ˜ ์žˆ๋‹ค(๊ฐœ๋ฐœ PC์™€ ์„œ๋ฒ„ PC๊ฐ€ ๋‹ค๋ฅผ ๊ฐ€๋Šฅ์„ฑ์ด ๋งค์šฐ ํฌ๊ธฐ ๋•Œ๋ฌธ). ๋”ฐ๋ผ์„œ ํŒŒ์ผ ์—…๋กœ๋“œ์™€ ์ €์žฅ ์‹œ์— ๊ฒฝ๋กœ๋ฅผ ๋™์ ์œผ๋กœ ์•Œ์•„๋‚ด๋Š” ์ž‘์—…์ด ํ•„์š”ํ•˜๋‹ค.

 

 

 

 

ServletContext๋ฅผ ์–ป์–ด์„œ ์ ˆ๋Œ€ ๊ฒฝ๋กœ๋ฅผ ์–ป์–ด๋‚ผ ์ˆ˜๋„ ์žˆ๊ณ , HttpServletRequest๋ฅผ ํ†ตํ•ด ์ ˆ๋Œ€ ๊ฒฝ๋กœ๋ฅผ ์–ป์–ด๋‚ผ ์ˆ˜๋„ ์žˆ๋‹ค. ๊ฒฝ๋กœ๋ฅผ ์–ป์–ด๋‚ธ ํ›„์—๋Š” ํŒŒ์ผ ๊ฐ์ฒด๋ฅผ ๋งŒ๋“ค์–ด์„œ ์ „์†กํ•˜๋ฉด ๋œ๋‹ค.

 

 

 

NoticeController.java

@Controller("adminNoticeController")
@RequestMapping("/admin/board/notice/")
public class NoticeController {
	
	@Autowired
	private ServletContext ctx;
	
	@RequestMapping("reg")
	@ResponseBody
	public String reg(String title, String content, MultipartFile file, String category, String[] foods, String food, HttpServletRequest request) {
		
		//ํŒŒ์ผ ์—…๋กœ๋“œ
		String fileName = file.getOriginalFilename();
		long fileSize = file.getSize();
		System.out.printf("fileName:%s, fileSize:%d\n", fileName, fileSize);
		
		
		//webapp/static/upload ํด๋” ์•ˆ์— ํŒŒ์ผ์„ ์ €์žฅํ•  ๊ฒƒ์ด๋‹ค.
		//ํด๋”์˜ ์ ˆ๋Œ€๊ฒฝ๋กœ(D:.....)๋ฅผ  ์“ฐ์ง€ ์•Š๊ณ (๊ฐœ๋ฐœpc์™€ ์šด์˜์„œ๋ฒ„pc์˜ ๊ฒฝ๋กœ๊ฐ€ ์ผ๋ฐ˜์ ์œผ๋กœ ๋‹ค๋ฅด๊ธฐ ๋•Œ๋ฌธ)
		
//		ServletContext ctx = request.getServletContext(); //=>์ด๋ ‡๊ฒŒ ํ•ด๋„ ๋จ. ์—ฌ๊ธฐ์„  ํ•„๋“œ๋กœ ์„ ์–ธํ•จ.
		
		String webPath = "/static/upload";
		String realPath = ctx.getRealPath(webPath);
		System.out.printf("realPath: %s\n", realPath);
        
		File savePath = new File(realPath); //์ €์žฅ ๊ฒฝ๋กœ์ธ realPath
        
		//์—…๋กœ๋“œ ํ•˜๊ธฐ ์œ„ํ•œ ๊ฒฝ๋กœ๊ฐ€ ์—†์„ ๊ฒฝ์šฐ์—๋Š” ๊ทธ ๊ฒฝ๋กœ๋ฅผ ์ง์ ‘ ์ƒ์„ฑํ•˜๊ฒŒ ํ•จ
		//exists() : ๊ฒฝ๋กœ๊ฐ€ ์กด์žฌํ•˜๋Š”์ง€ ์•„๋‹Œ์ง€ ๋ฐ˜ํ™˜(boolean)
		if(!savePath.exists()) {
			savePath.mkdirs(); //๊ฒฝ๋กœ๊ฐ€ ์—†๋‹ค๋ฉด, ๋””๋ ‰ํ† ๋ฆฌ ์ƒ์„ฑ
				/*
				mkdir : ๋งจ ๋ ๊ฒฝ๋กœ ํ•˜๋‚˜๋งŒ ์ƒ์„ฑ
				mkdirs : ์ค‘๊ฐ„ ๊ฒฝ๋กœ๋ถ€ํ„ฐ ์—†์œผ๋ฉด ์ „๋ถ€ ์ƒ์„ฑ
				*/
		}
        
		realPath += File.separator + fileName; 
		//realPath ๋’ค์— ์—ญ์Šฌ๋ž˜์‹œ(\)๊ฐ€ ๋ถ™๊ณ  ํŒŒ์ผ ์ด๋ฆ„์ด ๋”ํ•ด์ ธ์•ผ ํ•˜๋Š”๋ฐ, 
		//์œˆ๋„์šฐ๊ฐ€ ์•„๋‹Œ ๊ฒฝ์šฐ์—๋Š” ๊ตฌ๋ถ„์ž๊ฐ€ ์—ญ์Šฌ๋ž˜์‹œ๊ฐ€ ์•„๋‹ ์ˆ˜ ์žˆ์Œ. 
		//separator๋Š” ํ˜„์žฌ ์‹œ์Šคํ…œ์— ๋งž๊ฒŒ ๊ตฌ๋ถ„์ž๋ฅผ ๋งŒ๋“ค์–ด์ฃผ๋Š” ์—ญํ• ์„ ํ•จ
		
		File saveFile = new File(realPath); //ํŒŒ์ผ ๊ฐ์ฒด๋ฅผ ๋งŒ๋“ ๋‹ค. => ๊ป๋ฐ๊ธฐํŒŒ์ผ(๊ฒฝ๋กœ+ํŒŒ์ผ๋ช…)
		file.transferTo(saveFile); //์—…๋กœ๋“œํ•œ ํŒŒ์ผ ๋ฐ์ดํ„ฐ์— '๊ฒฝ๋กœ+ํŒŒ์ผ๋ช…' ๊ป๋ฐ๊ธฐ๋ฅผ ์ž…ํžŒ๋‹ค.
	}
}

 

์—…๋กœ๋“œํ•œ ํŒŒ์ผ์„ ์ €์žฅํ•  upload ํด๋”๋ฅผ static ํด๋” ์•ˆ์— ์ƒ์„ฑํ•œ๋‹ค. ๋จผ์ € HttpServletRequest๋ฅผ ํ†ตํ•ด ์ ˆ๋Œ€ ๊ฒฝ๋กœ๋ฅผ ์•Œ์•„๋‚ด๊ธฐ ์œ„ํ•ด ๋ฉ”์†Œ๋“œ์—์„œ HttpServletRequest ๊ฐ์ฒด๋ฅผ ์–ป์–ด์˜จ๋‹ค.

 

"/static/upload"๋ฅผ web path๋กœ ์ง€์ •ํ•˜๊ณ , ServletContext์˜ getRealPath๋ฅผ ์ด์šฉํ•˜๋ฉด ๊ทธ ๊ฒฝ๋กœ๋ฅผ ํ†ตํ•ด ์ ˆ๋Œ€ ๊ฒฝ๋กœ ๊ฐ’์„ ์–ป์–ด์˜ฌ ์ˆ˜ ์žˆ๋‹ค. ServletContext๋Š” ๋ฉ”์†Œ๋“œ ์•ˆ์—์„œ request๋ฅผ ์ด์šฉํ•ด ๋ฐ›์•„์˜ฌ ์ˆ˜๋„ ์žˆ์ง€๋งŒ ํŠนํžˆ ์ „์—ญ์ ์œผ๋กœ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด ํ•„๋“œ์— ์„ ์–ธํ•˜์—ฌ ์ฃผ์ž…ํ•ด๋„ ๋œ๋‹ค. (์ด ๊ฒฝ์šฐ HttpServletRequest request ์—†์–ด๋„ ๋จ)

 

์Šคํ”„๋ง์€ ServletContext ๊ฐ์ฒด๋ฅผ IoC ์ปจํ…Œ์ด๋„ˆ์— ๋‹ด์•„๋‘๊ณ  ์žˆ๊ธฐ ๋•Œ๋ฌธ์— @Autowired๋ฅผ ์ด์šฉํ•ด ๊บผ๋‚ด ์“ธ ์ˆ˜ ์žˆ๋‹ค.

 

 

์ฝ˜์†” ์ถœ๋ ฅ๊ฐ’ (real path)

 

realPath: D:\....workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\webprj\static\upload

 

์›Œํฌ์ŠคํŽ˜์ด์Šค์˜ .metadata ํด๋” ์•ˆ์— ์‹ค์ œ ์ €์žฅ ๊ฒฝ๋กœ๊ฐ€ ์ƒ์„ฑ๋˜์–ด ์žˆ๋‹ค. ํŒŒ์ผ ์—…๋กœ๋“œ ์‹œ ์ด ๊ฒฝ๋กœ์— ํŒŒ์ผ์„ ์ €์žฅํ•˜๊ฒŒ ๋œ๋‹ค. 

 

realPath๋ฅผ ์ €์žฅํ•  ๊ป๋ฐ๊ธฐ ํŒŒ์ผ ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•œ๋‹ค. (File savePath = new File(realPath);)

์ด ๊ฒฝ๋กœ ํด๋”๊ฐ€ ์—†์„ ๋•Œ ๋ฐœ์ƒ๋˜๋Š” ์—๋Ÿฌ๋ฅผ ๋ฐฉ์ง€ํ•˜๊ธฐ ์œ„ํ•ด์„œ ๊ฒฝ๋กœ๊ฐ€ ์žˆ๋Š”์ง€ ๊ฒ€์‚ฌ ํ›„์— ์—†์œผ๋ฉด ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ์ƒ์„ฑํ•˜๊ฒŒ ํ•˜๋Š” ์กฐ๊ฑด๋ฌธ์„ ๊ฑฐ์น˜๊ฒŒ ํ•œ๋‹ค.

 

๊ทธ ํ›„์—๋Š” realPath์— ๊ตฌ๋ถ„์ž(File.separator)์™€ ํŒŒ์ผ๋ช…(fileName)์„ ๋”ํ•ด ์ €์žฅํ•œ๋‹ค. ์—ญ์Šฌ๋ž˜์‹œ๋ฅผ ์ถ”๊ฐ€ํ•˜์ง€ ์•Š๊ณ  separator๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์ด์œ ๋Š”, ์œˆ๋„์šฐ๊ฐ€ ์•„๋‹Œ ๊ฒฝ์šฐ์—๋Š” ์—ญ์Šฌ๋ž˜์‹œ๊ฐ€ ์•„๋‹ˆ๋ผ ์Šฌ๋ž˜์‹œ๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. separator๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์‹œ์Šคํ…œ ํ™˜๊ฒฝ์— ๋งž๋Š” ๊ตฌ๋ถ„์ž๋ฅผ ๋„ฃ์–ด์ฃผ๋Š” ์—ญํ• ์„ ํ•œ๋‹ค.

 

๊ทธ ํ›„ ๊ฒฝ๋กœ+ํŒŒ์ผ๋ช…์ด ๋”ํ•ด์ง„ realPath๋กœ ํŒŒ์ผ ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๋Š”๋ฐ, ์ด๋Š” ๊ป๋ฐ๊ธฐ ํŒŒ์ผ์ด๋ผ๊ณ  ์ƒ๊ฐํ•˜๋ฉด ๋œ๋‹ค. transferTo๋ฅผ ์ด์šฉํ•ด์„œ, form ํŒŒ์ผ์—์„œ ๋„˜์–ด์˜จ ๋ฐ์ดํ„ฐ์ธ file์— ๊ป๋ฐ๊ธฐ๋ฅผ ์ž…ํ˜€์„œ ์ €์žฅํ•œ๋‹ค.

 

 

 

* ๋‹ค์ค‘ ํŒŒ์ผ ์—…๋กœ๋“œ

 

๋ช‡ ๊ฐ€์ง€ ์‚ฌํ•ญ๋งŒ ๋ฐ”๊พธ๋ฉด ๋‹ค์ค‘ ํŒŒ์ผ ์—…๋กœ๋“œ๋ฅผ ๊ฐ„๋‹จํžˆ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ๋‹ค.

 

reg1.html

<tr>
	<th>์ฒจ๋ถ€ํŒŒ์ผ</th>
	<td colspan="3" class="text-align-left text-indent"><input type="file" name="files" /> </td>
</tr>
<tr>
	<th>์ฒจ๋ถ€ํŒŒ์ผ</th>
	<td colspan="3" class="text-align-left text-indent"><input type="file" name="files" /> </td>
</tr>

 

input type="file"์„ ํ•˜๋‚˜ ๋” ์ถ”๊ฐ€ํ•˜๊ณ , ๋‹ค์ค‘ ํŒŒ์ผ ์—…๋กœ๋“œ์ด๋ฏ€๋กœ name์„ files๋กœ ์ˆ˜์ •ํ•˜์˜€๋‹ค. ๊ฐ™์€ name์œผ๋กœ ์—ฌ๋Ÿฌ๊ฐœ์˜ ๊ฐ’์ด ์ „๋‹ฌ๋˜๋ฉด ๋ฐฐ์—ด๋กœ ๋ฐ›์„ ์ˆ˜ ์žˆ๋‹ค.

 

 

NoticeController.java

	@RequestMapping("reg")
	@ResponseBody
	public String reg(String title, String content, MultipartFile[] files, String category, String[] foods, String food/*, HttpServletRequest request*/) throws IllegalStateException, IOException {
		
		for(MultipartFile file : files) {
		
			String fileName = file.getOriginalFilename();
			long fileSize = file.getSize();
			System.out.printf("fileName:%s, fileSize:%d\n", fileName, fileSize);
						
			String webPath = "/static/upload";
			String realPath = ctx.getRealPath(webPath);
			System.out.printf("realPath: %s\n", realPath);
			
			File savePath = new File(realPath); 
	
			if(!savePath.exists()) { //๊ฒฝ๋กœ๊ฐ€ ์—†๋‹ค๋ฉด
				savePath.mkdirs(); //๋””๋ ‰ํ† ๋ฆฌ ์ƒ์„ฑํ•œ๋‹ค.
			}
			
			realPath += File.separator + fileName; //realPath ๋’ค์— ์—ญ์Šฌ๋ž˜์‹œ(\)๊ฐ€ ๋ถ™๊ณ  ํŒŒ์ผ ์ด๋ฆ„์ด ๋”ํ•ด์ ธ์•ผ ํ•˜๋Š”๋ฐ, ์œˆ๋„์šฐ๊ฐ€ ์•„๋‹Œ ๊ฒฝ์šฐ์—๋Š” ๊ตฌ๋ถ„์ž๊ฐ€ ์—ญ์Šฌ๋ž˜์‹œ๊ฐ€ ์•„๋‹ ์ˆ˜ ์žˆ์Œ. separator๋Š” ํ˜„์žฌ ์‹œ์Šคํ…œ์— ๋งž๊ฒŒ ๊ตฌ๋ถ„์ž๋ฅผ ๋งŒ๋“ค์–ด์ฃผ๋Š” ์—ญํ• ์„ ํ•จ
			
			File saveFile = new File(realPath); //ํŒŒ์ผ ๊ฐ์ฒด๋ฅผ ๋งŒ๋“ ๋‹ค. (๊ฒฝ๋กœ+ํŒŒ์ผ๋ช…) => ๊ป๋ฐ๊ธฐ ํŒŒ์ผ
			file.transferTo(saveFile); //์—…๋กœ๋“œํ•œ ํŒŒ์ผ ๋ฐ์ดํ„ฐ๋ฅผ ์ง€์ •ํ•œ ํŒŒ์ผ์— ์ €์žฅ. ์œ„์—์„œ ๋งŒ๋“  ๊ป๋ฐ๊ธฐ ํŒŒ์ผ saveFile์„ ์ž…ํžŒ๋‹ค.
		
		}
		return String.format("title:%s, content:%s<br>category:%s, food:%s", title, content, category, food);
	}

 

์–ป์–ด์˜ค๋Š” MultipartFile ๊ฐ์ฒด๋ฅผ ๋ฐฐ์—ด๋กœ ๋ฐ”๊พธ๊ณ  ๋ณ€์ˆ˜๋ช…์€ files์œผ๋กœ ์„ค์ •ํ•œ๋‹ค. (MultipartFile[] files)

์—ฌ๋Ÿฌ ํŒŒ์ผ์— ๋Œ€ํ•ด์„œ ํ•˜๋‚˜์”ฉ ์ €์žฅํ•  ์ˆ˜ ์žˆ๊ฒŒ for each๋ฌธ์„ ์‚ฌ์šฉํ•œ๋‹ค.