파일 첨부를 하지 않았는데, MultipartHttpServletRequest - getFiles 에서 사이즈가 1로 잡히는 문제
- 작성자 :
- 최*민
- 작성일 :
- 2023-09-08 19:49:34
- 조회수 :
- 581
- 구분 :
- 실행환경 / 3.1
- 진행상태 :
- 완료
Q
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
List<MultipartFile> files = multipartRequest.getFiles("files");
첨부를 하지 않을경우 files 변수의 isEmpty() 는 true가 나와야할 것 같은데, false가 나와서 문의드립니다.
dispatcher-servlet.xml에는 아래와 같이 설정되어 있습니다.
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- one of the properties available; the maximum file size in bytes -->
<property name="maxUploadSize">
<value>200000000</value>
</property>
<property name="uploadTempDir" ref="uploadDirResource" />
</bean>
<bean id="uploadDirResource" class="org.springframework.core.io.FileSystemResource">
<constructor-arg>
<value>D:/upload/test/</value>
</constructor-arg>
</bean>
참고로 첨부를 하면 정상적으로 첨부한 파일 갯수만큼 사이즈가 잡히고,
첨부하지 않을 경우 화면단에서 해당 form의 file이 undefined 나오는 것까지 확인했습니다.
List<MultipartFile> files = multipartRequest.getFiles("files");
첨부를 하지 않을경우 files 변수의 isEmpty() 는 true가 나와야할 것 같은데, false가 나와서 문의드립니다.
dispatcher-servlet.xml에는 아래와 같이 설정되어 있습니다.
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- one of the properties available; the maximum file size in bytes -->
<property name="maxUploadSize">
<value>200000000</value>
</property>
<property name="uploadTempDir" ref="uploadDirResource" />
</bean>
<bean id="uploadDirResource" class="org.springframework.core.io.FileSystemResource">
<constructor-arg>
<value>D:/upload/test/</value>
</constructor-arg>
</bean>
참고로 첨부를 하면 정상적으로 첨부한 파일 갯수만큼 사이즈가 잡히고,
첨부하지 않을 경우 화면단에서 해당 form의 file이 undefined 나오는 것까지 확인했습니다.
환경정보
-
- OS 정보 : win10
- 표준프레임워크 버전 : 3.1
- JDK(JRE) 정보 : 1.7
- WAS 정보 : tomcat v8.5
- DB 정보 :
- 기타 환경 정보 :
A
안녕하세요.
표준프레임워크센터입니다.
form내 file객체가 있는경우 파일 지정이 되지 않으면
MultipartFile 객체가 비어있는 상태로 생성됩니다.
따라서 List가 Empty가 아니므로 false가 나오는게 확인됩니다.
MultipartFile객체는 isEmpty에 대해 true로 결과가 나옵니다.
배포된 공통컴포넌트의 파일업로드 부분을 참고 하여
기능 테스트를 진행해 해보시기 바랍니다.
https://www.egovframe.go.kr/home/sub.do?menuNo=49
감사합니다.
표준프레임워크센터입니다.
form내 file객체가 있는경우 파일 지정이 되지 않으면
MultipartFile 객체가 비어있는 상태로 생성됩니다.
따라서 List가 Empty가 아니므로 false가 나오는게 확인됩니다.
MultipartFile객체는 isEmpty에 대해 true로 결과가 나옵니다.
배포된 공통컴포넌트의 파일업로드 부분을 참고 하여
기능 테스트를 진행해 해보시기 바랍니다.
https://www.egovframe.go.kr/home/sub.do?menuNo=49
감사합니다.