Single file upload means a client sends exactly one file to the server in a multipart/form-data request, and Spring Boot receives it as a MultipartFile. The application then validates the file, saves it somewhere (a folder, the database, or cloud storage), and keeps the file details for later use. It is used for profile pictures, ID proofs, resumes, and any feature where a user attaches one file to a record. In this example the image is saved in an uploads folder on disk, and only its details (name, type, size) are saved in MySQL.
Features
MultipartFilegives the file name, content type, size, and content- File size limits set in
application.properties - Validation of empty files and allowed image types (PNG, JPEG, GIF)
- A unique stored file name (UUID), so two uploads never overwrite each other and unsafe names such as
../../x.pngare never used - The
uploadsfolder is created automatically at startup - Replacing or deleting an image also removes the old file from the folder
- The stored image can be viewed in the browser through a GET URL.
