File upload problems in a Spring MVC application typically fall into three buckets: files that are too large, files of an unexpected type, and uploads that time out on slow connections, each requiring a different mitigation.
Key Points: • Oversized files should be rejected early using max-file-size and max-request-size limits rather than letting them exhaust memory or disk. • Content-type and extension checks (and ideally magic-byte validation) prevent disguised or malicious files from being accepted. • Slow uploads may need longer connection and read timeouts configured at the server or multipart resolver level. • Uploading directly to disk-backed temp storage instead of holding entire files in memory avoids OutOfMemoryErrors under load. • Returning clear validation errors to the client (file too large, wrong type) improves the user experience instead of a generic 500 error.
Example: A user attempting to upload a 200MB video to a form meant for profile photos should get an immediate, friendly "file exceeds 5MB limit" response rather than the server hanging or crashing mid-upload.
Code Example:
spring.servlet.multipart.max-file-size=5MB
spring.servlet.multipart.max-request-size=10MBInterview Tip: A concise interview answer is:
"The recurring issues are files exceeding size limits, wrong or spoofed file types, and timeouts on slow uploads. I address size with max-file-size and max-request-size properties, validate content type before processing, and tune server timeouts for larger files so legitimate slow uploads don't get killed prematurely."