Martin Sivák opened SPR-13849 and commented
The method argument resolver fails with org.springframework.web.multipart.MultipartException: The current request is not a multipart request when an optional MultipartFile argument is present in the request handler method during a plain POST request with no files included.
I would expect that multipart request is enforced when files are present, but not necessary when there are no files and the file argument is marked as optional.
{{
@RequestMapping(method = RequestMethod.POST)
@ResponseStatus(HttpStatus.OK)
public ResponseEntity<EmberModel> upload(@CurrentUser User currentUser,
@RequestParam(value = "file", required = false) MultipartFile file,
@RequestParam("entity") @Valid DocumentApiModel entity) throws IOException, BaseRestException {
}}
It seems that this can be "trivially" fixed in org.springframework.web.method.annotation.RequestParamMethodArgumentResolver.resolveName(RequestParamMethodArgumentResolver.java:167) by checking the optional attribute and the provided value.
Affects: 4.2.1
Issue Links:
Referenced from: commits b4f33ad
Martin Sivák opened SPR-13849 and commented
The method argument resolver fails with org.springframework.web.multipart.MultipartException: The current request is not a multipart request when an optional MultipartFile argument is present in the request handler method during a plain POST request with no files included.
I would expect that multipart request is enforced when files are present, but not necessary when there are no files and the file argument is marked as optional.
{{
@RequestMapping(method = RequestMethod.POST)@ResponseStatus(HttpStatus.OK)public ResponseEntity<EmberModel> upload(
@CurrentUserUser currentUser,@RequestParam(value = "file", required = false) MultipartFile file,@RequestParam("entity")@ValidDocumentApiModel entity) throws IOException, BaseRestException {}}
It seems that this can be "trivially" fixed in org.springframework.web.method.annotation.RequestParamMethodArgumentResolver.resolveName(RequestParamMethodArgumentResolver.java:167) by checking the optional attribute and the provided value.
Affects: 4.2.1
Issue Links:
@RequestPartReferenced from: commits b4f33ad