MultipartFile argument requires multipart request even when optional (and empty) [SPR-13849] #18422
Labels
in: web
Issues in web modules (web, webmvc, webflux, websocket)
type: enhancement
A general enhancement
Milestone
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:
@RequestPart
Referenced from: commits b4f33ad
The text was updated successfully, but these errors were encountered: