<img src="경로">
위 태그가 작성되어 있으면 브라우저(클라이언트)는 src에있는 경로를 서버에 요청
→ 클라이언트가 서버에 이미지 파일을 보내달라고 요청하는 HTTP 요청으로 처리
< 예시 > <form action="page/file/test" method="POST" enctype="multipart/form-data"> <input type="file" name="uploadFile> <button>제출하기</button> </form>
위와 같이 요청을 보낼 시,
서버는 /page/file/test 요청 주소와 매핑되어있는 서버 경로를 찾음
(config 파일에서 서버의 경로를 매핑)
MultipartConfigElement
파일 업로드를 처리하는데 사요되는 MultipartConfigElement를 구성하고 반환
파일 업로드를 위한 구성 옵션을 설정하는데 사용
업로드 파일의 최대크기, 메모리에서의 임시 저장경로 등 설정 가능
MultipartResolver
MultipartFile을 처리해주는 해결사
클라이언트로부터 받은 multipart 요청을 처리하고,
이 중에서 업로드된 파일을 추출하여 MultipartFile 객체로 제공하는 역할
<예시> @PostMapping("file/test") public String fileUpload(@RequestPara("uploadFile") MultipartFile uploadFile, RedirectAttributes ra) throws Exception{ String path = service.fileUpload(uploadFile); if(path != null ){ ra.addFlashAttribute("path", path); } return "redirect:/myPage/fileTest"; }
<예시> public String fileUpload(MultipartFile uploadFile) throws Exception{ if( uploadFile.isEmpty() ){ return null; } uploadFile.transferTo(new File("C:/uploadFiles/test/" +uploadFile.getOriginalFilename())); return "/myPage/file/" + uploadFile.getOriginalFilename(); }