๐ด The Error You're Seeing
Confirm this matches your console output. If it does, you're in the right place.
2026-03-01 13:05:55.800 WARN 8842 --- [nio-8080-exec-5] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.multipart.support.MissingServletRequestPartException: Required request part 'file' is not present]โก Quick Fix Works 80% of the time
Ensure the API client sends a multipart/form-data request with a part named 'file'.
// Backend:
@PostMapping("/upload")
public String upload(@RequestParam("file") MultipartFile file) { ... }
// Postman: Body -> form-data -> Key: file (Type: File), Value: select file๐ง Why this Happens
Tap to expand the deep technical explanation
Your controller method expects a multipart part named 'file' (usually a MultipartFile). When Spring parsed the incoming HTTP request, it couldn't find a part with that exact name in the multipart payload.
The HITEC City Parking Spot Analogy:
Imagine ordering a combo meal at a fast-food restaurant, but the cashier only hands you the fries and drink, forgetting the burger. The cashier (Spring) is missing a required part of the order.
๐ How to Reproduce Confirm this is your error
Send a multipart/form-data request without a part named 'file' to a @RequestPart MultipartFile endpoint. Spring returns 400 Required request part 'file' is not present.
๐ ๏ธ Solutions (3 Ways to Fix)
Send the correct multipart form data
๐ Use this if the backend is correct but the client isn't sending the file.
The @RequestParam("file") annotation tells Spring to look for a part named 'file' in the multipart payload. If the client doesn't include it, Spring throws this error.
// Postman Settings:
// 1. Go to Body
// 2. Select 'form-data'
// 3. Key: 'file' (hover and change type from Text to File)
// 4. Value: Select your fileMake the file optional
๐ Use this if the file upload is not strictly required.
Add required = false to the @RequestParam annotation.
@PostMapping("/upload")
public String upload(@RequestParam(name = "file", required = false) MultipartFile file) {
if (file == null || file.isEmpty()) {
return "No file uploaded";
}
return "File uploaded: " + file.getOriginalFilename();
}Fix Content-Type header
๐ Use this if you are manually setting headers in your HTTP client.
Do NOT manually set Content-Type to multipart/form-data. The HTTP client must set it automatically with the correct boundary string. If you hardcode it, Spring can't parse the parts.
// In Axios/Fetch:
// DO NOT DO THIS:
// headers: { 'Content-Type': 'multipart/form-data' }
// DO THIS: (Let the browser set it)
const formData = new FormData();
formData.append('file', selectedFile);
axios.post('/upload', formData);๐ Version Notes
Uses Servlet 3.0 multipart parsing under the hood.
Uses Jakarta Servlet 6.0 multipart parsing. Stricter boundaries.
๐ก๏ธ How to Prevent This Next Time
Always use Postman's 'File' type for form-data keys when testing file uploads. Never manually set the multipart Content-Type header in frontend code.