단일 파일 업로드를 위한 설정 / 파일 1탄
https://purple-j.tistory.com/213
파일 저장을 위한 설정
https://purple-j.tistory.com/212 main > webapp > WEB-INF > spring > servlet-context.xml에 아래 코드를 넣어준다 class="org.springframework.." data-og-host="purple-j.tistory.com" data-og-source-url="h..
purple-j.tistory.com
https://purple-j.tistory.com/214
다중 파일을 받아오기 위한 설정 / 파일 3탄
https://purple-j.tistory.com/213 webapp > WEB-INF > spring > servlet-context.xml에 아래 코드를 넣어준다 class="org.springframework.." data-og-host="purple-j.tistory.com" data-og-source-url="h.." dat..
purple-j.tistory.com
위 포스팅들과 이어지는 파일 포스팅 1탄
- spring web mvc 제작중
- sts4
- tomcat 9
- jdk 1.8
1. servlet-context.xml 설정
아래단 src > main > webapp > WEB-INF > spring > servlet-context.xml에 아래 코드를 넣어준다
- maxUploadSize는 파일의 최대 크기 지정 위의 314572800은 300mb이다.
2. pom.xml 설정
pom.xml에 아래 코드를 넣어준다.
3. html / jsp
- form의 enctype을 multipart/form-data로 적어준다.
4. controller
- 파라미터를 MultipartFile file로 받는다.
- file.getOriginalFilename() : 등록한 파일의 이름을 얻어올 수 있다
- file.getSize() : 파일 사이즈를 얻어올 수 있다.
* 코드는 길지만 사실상 다 필요 없고 파라미터를 MultipartFile로 받는 부분만 적어주면 됨
- 붙여넣기용 코드
# 참고자료
1. 파일 업로드 공부용
CommonsFileUploadSupport (Spring Framework 5.3.15 API)
Base class for multipart resolvers that use Apache Commons FileUpload 1.2 or above. Provides common configuration properties and parsing functionality for multipart requests, using a Map of Spring CommonsMultipartFile instances as representation of uploade
docs.spring.io
2. 인코딩 타입
https://www.w3schools.com/tags/att_form_enctype.asp
HTML form enctype Attribute
W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.
www.w3schools.com