MultipartFile을 @RequestParam 으로 받을때 파일을 지정하지 않으면 발생하는 에러...버근가요?

7,483 views
Skip to first unread message

Hwa Joon Lee

unread,
Jun 17, 2013, 9:05:15 PM6/17/13
to ks...@googlegroups.com
안녕하세요. 비가 주륵주륵 내리는 아침입니다.
 
여러개의 sns에 글을 한번에 올리게 혼자서 뚝딱거려보다가....MultipartFile 관련되서 의문 사항이 들어서 질문을 남겨봅니다...
 
포스트를 등록하는 로직을 키 노출이 꺼려져서 서버쪽에서 다 처리를 하다보니 이미지 파일을 MultipartFile 넘겨주고
 
서버에서 sns에 다시 올리도록 처리를 하고 있는데요.
 
private @ResponseBody Map<String, Object> distribute(
    @RequestParam(value="checkTwitter") Boolean checkTwitter,
    @RequestParam(value="checkFacebook") Boolean checkFacebook,
    @RequestParam(value="checkMe2day") Boolean checkMe2day,
    @RequestParam(value="body", required=false) String body,
    @RequestParam(value="link", required=false, defaultValue="") String link, 
    @RequestParam(value="image", required=false) MultipartFile image,
    @RequestParam(value="video", required=false) MultipartFile video,
    HttpServletResponse response
    ) throws Exception {
 
......
 
}
 
저런식으로 파라미터를 넘겨 받아 작업중이었습니다.
 
클라이언트단에서 jsp로 처음엔 jquery.form.js 를 이용해서 FormData로 넘길땐 문제가 없었는데 FormData가 ie10부터 된다는 충격적인 사실을 늦게 알고
 
다시 <form id="Form" name="Form" method="POST" enctype="multipart/form-data"> <input type="file" id="image" name="image"> ... </form> 태그를 사용해서 ajaxSubmit을 했습니다.
 
근데 그때부터 파일을 선택하지 않으면 오류가 떨어지기 시작하더군요...
 
2013-06-18 10:00:21,048 http-80-2 DEBUG [AbstractUrlHandlerMapping getHandlerInternal] Mapping [/data/api/distribute/distribute.json] to HandlerExecutionChain with handler [eucsystems.com.web.data.ContentDistribute@a4911d] and 1 interceptor
2013-06-18 10:00:21,054 http-80-2 DEBUG [BeanUtils findEditorByConvention] No property editor [org.springframework.web.multipart.MultipartFileEditor] found for type org.springframework.web.multipart.MultipartFile according to 'Editor' suffix convention
2013-06-18 10:00:21,054 http-80-2 DEBUG [AbstractHandlerExceptionResolver resolveException] Resolving exception from handler [systems.com.web.data.ContentDistribute@a4911d]: org.springframework.beans.ConversionNotSupportedException: Failed to convert value of type 'java.lang.String' to required type 'org.springframework.web.multipart.MultipartFile'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [org.springframework.web.multipart.MultipartFile]: no matching editors or conversion strategy found
2013-06-18 10:00:21,059 http-80-2 DEBUG [AbstractHandlerExceptionResolver resolveException] Resolving exception from handler [systems.com.web.data.ContentDistribute@a4911d]: org.springframework.beans.ConversionNotSupportedException: Failed to convert value of type 'java.lang.String' to required type 'org.springframework.web.multipart.MultipartFile'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [org.springframework.web.multipart.MultipartFile]: no matching editors or conversion strategy found
2013-06-18 10:00:21,059 http-80-2 DEBUG [AbstractHandlerExceptionResolver resolveException] Resolving exception from handler [systems.com.web.data.ContentDistribute@a4911d]: org.springframework.beans.ConversionNotSupportedException: Failed to convert value of type 'java.lang.String' to required type 'org.springframework.web.multipart.MultipartFile'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [org.springframework.web.multipart.MultipartFile]: no matching editors or conversion strategy found
 
어쩔수 없이 MultipartHttpServletRequest 추가 하고
 
MultipartFile image = request.getFile("image");
MultipartFile video = request.getFile("video");
 
이런식으로 처리를 하니 정상 작동은 하는데....
 
위에서 왜 에러가 떨어지는지 이해가 안되서요...
 
허접한 질문 읽어주셔서 감사하구요... 한말씀 남겨주시면 더욱 감사하겠습니다.
 
그럼 오늘도 좋은 하루 되시길 바랍니다.
 
 

애너벨리

unread,
Jun 17, 2013, 9:45:14 PM6/17/13
to ks...@googlegroups.com
@RequestPart 로 바꿔서 해보세요 ~

애너벨리

unread,
Jun 17, 2013, 9:45:31 PM6/17/13
to ks...@googlegroups.com
@RequestParam -> @RequestPart

Hwa Joon Lee

unread,
Jun 17, 2013, 10:27:47 PM6/17/13
to ks...@googlegroups.com
아 3.0.5를 쓰고 있었는데 3.1로 올려서 테스트 해봐야겠네요.^^ 답변 감사합니다.
Reply all
Reply to author
Forward
0 new messages