Spring Boot REST API : Upload & Download files
📦 Tech Stack
- Spring Boot
- Spring Web (REST)
- Multipart support (
MultipartFile
) - File System for storage
📁 1. Maven Dependencies (pom.xml
)
🛠️ 2. Controller Class – File Upload & Download
📂 3. Create Upload Directory
Manually create a folder in your project root:
Or ensure the controller creates it dynamically, as shown.
🔄 4. Test with Postman or Curl
Upload a File:
- Method:
POST
- URL:
http://localhost:8080/api/files/upload
- Form-Data: Key =
file
, Value = your file
Download a File:
- Method:
GET
- URL:
http://localhost:8080/api/files/download/sample.txt
✅ Bonus: Return JSON Metadata
You can also return file size, content-type, or saved path in the response instead of a simple string.