Amazon S3 – SpringBoot RestAPIs List All Files in S3 Bucket

In the tutorial, we build a SpringBoot RestAPIs to list all files in a Amazon S3 bucket.

Previous post:
Amazon S3 – SpringBoot RestAPIs Upload/Download File/Image to S3

Technologies

  • Java 8
  • Maven 3.6.1
  • pring Tool Suite: 3.9.4.RELEASE
  • Spring Boot: 2.0.4.RELEASE
  • Amazon S3

S3 List Files in Bucket

The below segment code for List ALL file in S3 Bucket:

-> If you just want to list all files in a specific S3 folder, you can configure such as:

Practice

We re-use all the sourcecode of the previous tutorial:

-> Amazon S3 – SpringBoot RestAPIs Upload/Download File/Image to S3

springboot-restapi-amazon-s3-list-all-file + project-structure

What we build more? ->

  • Implement listFiles service
  • Expose listAllFiles RestAPI
Implement S3 listFiles service

– Add listFiles function in S3Services.java interface:

– Implement listFiles in S3ServicesImpl.java:

Expose List Files RestAPI

In DownloadFileController.java, expose a new API -> @GetMapping("/api/files")

Run & Check results

Build and Run the SpringBoot sourcecode with commandlines {mvn clean install, mvn spring-boot:run}.

– All Files in Amazon S3:

springboot-restapi-amazon-s3-list-all-file + s3 files

– List all files with RestAPI:

springboot-restapi-amazon-s3-list-all-file + list-files

SourceCode

– In application.properties file, change gkz.aws.access_key_id & gkz.aws.secret_access_key to yours.

– Sourcecode ->

SpringS3Amazon

By grokonez | August 5, 2018.



Related Posts


1 thought on “Amazon S3 – SpringBoot RestAPIs List All Files in S3 Bucket”

  1. I need a help!
    I want a Java client application which should built on spring Boot. And that client application should hit the AWS payment gateway and get the bill amount for that service.
    Please kindly help me with the code.

Got Something To Say:

Your email address will not be published. Required fields are marked *

*