You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I'm trying to upload a file via multipart/form-data request. The handler method requires one object parameter, which contains a field of type javax.servelet.http.Part. As MultipartFile typed field can be resolved with parts, I've expected the same from Part.
As described in senario 7 (from related issue #15220), Part field could not be bind with values, as StandardMultipartHttpServletRequest wraps Part into private class StandardMultipartHttpServletRequest.StandardMultipartFile.
In turn, conversion from StandardMultipartFile to Part had occured but failed.
Test and generated logs are below. I hope available approaches are found for this scenario.
@SpringJUnitWebConfig(classes = {WebConfig.class})
publicclassFileUploadControllerTests {
MockMvcmvc;
FileUploadControllercontroller = newFileUploadController();
MockPartmockPart = newMockPart("file", "filename.png", "file".getBytes());
@BeforeEachpublicvoidsetup() {
this.mvc = MockMvcBuilders.standaloneSetup(controller).build();
}
@DisplayName("params + Part -> VO Having Part : 400 Error")
@TestvoidbindVOHavingPart() throwsException {
MultipartHttpServletRequestrequest = (MultipartHttpServletRequest)
mvc.perform(multipart("/vopart")
.part(mockPart)
.param("name", "jaebin-joo")
.param("age", "11"))
.andExpect(status().is4xxClientError()) // StandardMultipartFile 타입을 Part로 변환할 수 없기 때문에
.andReturn().getRequest();
assertThat(request.getParts().size()).isEqualTo(1);
assertThat(request.getMultiFileMap().size()).isEqualTo(0);
}
}
main] DEBUG org.springframework.web.method.HandlerMethod - Could not resolve parameter [0] in public org.springframework.http.ResponseEntity org.binchoo.study.spring.multipart.profileservice.controller.FileUploadControllerTests$FileUploadController.bindVOHavingPart(org.binchoo.study.spring.multipart.profileservice.controller.FileUploadControllerTests$UserHavingPartVO): org.springframework.validation.BeanPropertyBindingResult: 1 errors
Field error in object 'userHavingPartVO' on field 'file': rejected value [org.springframework.web.multipart.support.StandardMultipartHttpServletRequest$StandardMultipartFile@4e974b9e]; codes [typeMismatch.userHavingPartVO.file,typeMismatch.file,typeMismatch.javax.servlet.http.Part,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [userHavingPartVO.file,file]; arguments []; default message [file]]; default message [Failed to convert value of type 'org.springframework.web.multipart.support.StandardMultipartHttpServletRequest$StandardMultipartFile' to required type 'javax.servlet.http.Part'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'org.springframework.web.multipart.support.StandardMultipartHttpServletRequest$StandardMultipartFile' to required type 'javax.servlet.http.Part': no matching editors or conversion strategy found]
The text was updated successfully, but these errors were encountered:
Affects: 5.3.2
Related issue: #15220
Hello, I'm trying to upload a file via multipart/form-data request. The handler method requires one object parameter, which contains a field of type
javax.servelet.http.Part
. AsMultipartFile
typed field can be resolved with parts, I've expected the same fromPart
.As described in senario 7 (from related issue #15220),
Part
field could not be bind with values, asStandardMultipartHttpServletRequest
wrapsPart
into private classStandardMultipartHttpServletRequest.StandardMultipartFile
.In turn, conversion from
StandardMultipartFile
toPart
had occured but failed.Test and generated logs are below. I hope available approaches are found for this scenario.
The text was updated successfully, but these errors were encountered: