Skip to content

Bind multipart files in ProxyingHandlerMethodArgumentResolver. - #3538

Open
jmsmg wants to merge 1 commit into
spring-projects:mainfrom
jmsmg:multipart-projection-1136
Open

jmsmg wants to merge 1 commit into
spring-projects:mainfrom
jmsmg:multipart-projection-1136

Conversation

@jmsmg

@jmsmg jmsmg commented Sep 10, 2026

Copy link
Copy Markdown

Interface-based form-backing objects created by ProxyingHandlerMethodArgumentResolver return null for MultipartFile properties, see #1136.

Cause. createAttribute binds request.getParameterMap() only. The files of a multipart request live in MultipartRequest#getMultiFileMap(), so they never reach the Map backing the projection proxy, and bindRequestParameters is a no-op, so there is no second binding pass either. In a @NullMarked context the proxy's nullness validation turns the null into a NullPointerException ("Return value is null but must not be null").

Change. createAttribute now also adds the files of a MultipartRequest to the property values, following WebDataBinder#bindMultipart: a single file is bound as is, multiple files for the same name as a List<MultipartFile>. Requests without a MultipartRequest are unaffected.

Tests. Two unit tests in ProxyingHandlerMethodArgumentResolverUnitTests (bindsMultipartFileIntoProjectedPayload, bindsMultipleMultipartFilesIntoProjectedPayload) resolve a @ProjectedPayload interface from a MockMultipartHttpServletRequest. Both fail without the change and pass with it; EnableSpringDataWebSupportIntegrationTests still passes.

Open question. I kept the change local to the resolver. Alternatively MapDataBinder could extend WebRequestDataBinder and use bind(WebRequest), which would additionally bind Servlet Parts when no MultipartResolver is configured. Happy to switch if you prefer that route.

Closes #1136

  • You have read the Spring Data contribution guidelines.
  • You use the code formatters provided here and have them applied to your changes. Don’t submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.
  • You added yourself as author in the headers of the classes you touched. Amend the date range in the Apache license header if needed. For new types, add the license header (copy from another file and set the current year only).

ProxyingHandlerMethodArgumentResolver only bound the request parameter map, so the files of a multipart request never reached the map backing the projection proxy and a MultipartFile property of a @ProjectedPayload interface always resolved to null. The resolver now also binds the files of a MultipartRequest the same way WebDataBinder does: a single file as is, multiple files for the same name as a List.

Closes spring-projects#1136

Signed-off-by: Seonggon Cho <jmsmg1@me.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ProxyingHandlerMethodArgumentResolver does not work with MultipartFile [DATACMNS-668]

2 participants