Skip to content

MultipartFile argument requires multipart request even when optional (and empty) [SPR-13849] #18422

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spring-projects-issues opened this issue Jan 7, 2016 · 0 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jan 7, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants