๐Ÿ”ด The Error You're Seeing

Confirm this matches your console output. If it does, you're in the right place.

ERROR LOG2026-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)

Solution 1โœ“ Most common cause

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 file
Solution 2

Make 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(); }
Solution 3

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

Spring Boot 2.x

Uses Servlet 3.0 multipart parsing under the hood.

Spring Boot 3.x

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.

Course Search
Search across all chapters & stages
๐Ÿ“–

Search the course

Type any topic โ€” branching, stash, rebase, hooks โ€” and jump straight to that chapter.

merge branchesgit stashundo commitrebase