-
Notifications
You must be signed in to change notification settings - Fork 38.4k
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
MultipartFile is Null in @ModelAttribute with Spring Boot 3.3.4 but Works in 3.2.4 #33791
Comments
move to spring-boot repository |
@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. |
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:
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 |
I had the same issue, I just used |
I solved it by using |
After a deeper look, seems to be triggered by adding |
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 becomesnull
. 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
Controller Setup:
Send a POST Request:
/users
POST
multipart/form-data
imageFile
: [Attach a file]gender
: [Provide appropriate value]Observe the Behavior:
imageFile
isnull
.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 isnull
when handling the POST request, whereas it works as expected in 3.2.4.Additional Information
Request
Looking for assistance or a fix to ensure that
MultipartFile
is correctly populated in Spring Boot 3.3.4 when using@ModelAttribute
.The text was updated successfully, but these errors were encountered: