Member-only story
Spring Boot file upload example
In this article, You’ll learn how to upload files using spring boot rest API.
- Uploading files are very common tasks. For which developers need to write code in their applications.
- We’ll first build the REST API for uploading file, and then test those API using Postman.
First Create Spring Boot Project Using Start.spring.io
Now, Let’s configure our Spring Boot application to enable Multipart file uploads, and define the maximum file size that can be uploaded. We’ll also configure the directory into which all the uploaded files will be stored.
Open src/main/resources/application.properties file, and add the following properties to it -
#Multipart Properties
# Enable multipart uploads
spring.servlet.multipart.enabled=true
# Threshold after which files are written to disk.
spring.servlet.multipart.file-size-threshold=2KB
# Max file size.
spring.servlet.multipart.max-file-size=2MB
# Max Request Size
spring.servlet.multipart.max-request-size=2MB
## File Storage Properties
# All files uploaded through the REST API will be stored in this…