Title: MultipartFile is Null in @ModelAttribute with Spring Boot 3.3.4 but Works in 3.2.4

Description:

When upgrading from Spring Boot version 3.2.4 to 3.3.4, the MultipartFile parameter in the controller method becomes null. This issue does not occur in version 3.2.4, where the file is correctly received. There are no restrictions on file size or other related configurations.

Steps to Reproduce 1. Controller Setup:

```kotlin
@PostMapping("/users")
fun insertTryOnFace(
    @ModelAttribute imageFile: MultipartFile,
    @ModelAttribute gender: Gender,
) {
    // Implementation
}
```
  1. Send a POST Request:
  2. Endpoint: /users
  3. Method: POST
  4. Content-Type: multipart/form-data
  5. Parameters:

    • imageFile: [Attach a file]
    • gender: [Provide appropriate value]
  6. Observe the Behavior:

  7. Spring Boot 3.3.4: imageFile is null.
  8. Spring Boot 3.2.4: imageFile is correctly received.

Expected Behavior The MultipartFile should be correctly populated with the uploaded file data regardless of the Spring Boot version, provided there are no size or configuration restrictions.

Actual Behavior In Spring Boot 3.3.4, the imageFile parameter is null when handling the POST request, whereas it works as expected in 3.2.4.

Additional Information - Spring Boot Versions: - Affected: 3.3.4 - Working: 3.2.4 - File Size Limits: No restrictions set; default configurations are used. - Environment: MacOs - Relevant Dependencies: jvmTarget 17, kotlinVersion 2.0.21, io.spring.dependency-management 1.1.6

Request Looking for assistance or a fix to ensure that MultipartFile is correctly populated in Spring Boot 3.3.4 when using @ModelAttribute.

Comment From: kkong101

move to spring-boot repository

Comment From: bclozel

@kkong101 at a quick glance, I don't think this is due to a behavior change in Spring Boot but probably in Spring Framework. Please let us know assess the situation and we'll move the issue back to Spring Boot if necessary. This issue was moved to Spring Framework on purpose.

Comment From: bclozel

I couldn't reproduce this problem with Spring Boot 3.3.5.

I've used the following controller:

package org.example.formfile;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

@Controller
public class FormController {

    private static final Log logger = LogFactory.getLog(FormController.class);

    @PostMapping(path = "/users", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    @ResponseBody
    public String insertTryOnFace(@ModelAttribute MultipartFile imageFile) {
        logger.info("file name: " + imageFile.getOriginalFilename());
        logger.info("file size: " + imageFile.getSize());

        return imageFile.getOriginalFilename();
    }

}

and issued the following request:

curl -v -F imageFile=@file.txt http://localhost:8080/users
* Host localhost:8080 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
*   Trying [::1]:8080...
* Connected to localhost (::1) port 8080
> POST /users HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/8.7.1
> Accept: */*
> Content-Length: 230
> Content-Type: multipart/form-data; boundary=------------------------o0UOAd4nXSat6Fym1GH9Od
>
* upload completely sent off: 230 bytes
< HTTP/1.1 200
< Content-Type: text/plain;charset=UTF-8
< Content-Length: 8
< Date: Mon, 28 Oct 2024 13:02:56 GMT
<
* Connection #0 to host localhost left intact
file.txt% 

There's probably something else going on, so I'm closing this issue for now. We can reopen if you can provide a minimal sample application.

Comment From: EnyaEnya

There's probably something else going on, so I'm closing this issue for now. We can reopen if you can provide a minimal sample application.

@bclozel I have the same problem, here is a sample

https://github.com/EnyaEnya/multipart-null

Comment From: Panfloeter

@bclozel We experience the same problem after upgrading from Spring Boot 3.3.1 to 3.4.2 and don't quite understand why this issue was closed. With the sample of @EnyaEnya at hand, could you re-analyze the problem and provide a fix and/or workaround? Thanks a lot!