Let’s create the simplest file upload download API with Spring boot

Heshani Samarasekara
1 min readMar 3, 2024

--

Hey there! This blog is about creating the simplest file upload download API with Spring boot 3.

I start by generating the Spring boot project with Spring Initializr. I add only one dependency, Spring Web. As you can see, I’m using Spring boot version 3.2.3 with Java 17.

Controller

In this example, I will expose 3 API endpoints.

i. List existing files

ii. Upload a new file

iii. Download an existing file

The controller code looks like below. We have @RequestMapping(“/file”) which says, all out API calls will be starting with /file in the front.

Then you see, there are 3 endpoints, 2 Get and 1 Post.

Service

In the service layer, we have the methods to cater all our controller methods. The Service layer looks like this.

I have given the file upload path in the application.properties file, and this can be configured as needed.

Find the full code here in github.

In the next blog, we’ll write a test suite to test our multipart application.

--

--