This is a simple storage SDK for Spring Boot applications. It provides a simple way to store and retrieve files from the file system.
<parent>
<groupId>br.com.senioritymeter</groupId>
<artifactId>parent</artifactId>
<version>1.0.1</version>
</parent>
@SpringBootApplication(scanBasePackages = {"br.com.senioritymeter", "your.package.name.here"})
<dependencies>
<dependency>
<groupId>br.com.senioritymeter</groupId>
<artifactId>storage</artifactId>
<version>1.0.3</version>
</dependency>
</dependencies>
spring:
cloud:
aws:
credentials:
access-key: ${AWS_ACCESS_KEY:sm-spring-storage-access-key}
secret-key: ${AWS_SECRET_KEY:sm-spring-storage-secret-key}
storage:
aws-s3:
enabled: true
region: ${AWS_REGION:sa-east-1}
bucket:
name: ${AWS_S3_BUCKET_NAME:sm-spring-storage-bucket-name}
Inject the StorageCreation
bean in your class and use it to save files.
private final StorageCreation storageCreation;
Prepare your payload and call the execute
method.
final var input = StorageCreation.Input.builder()
.fileArray(new byte[0])
.filename("filename.extension")
.domain("path/on/aws") // without "/" at the beginning and at the end
.type(StorageType.AWS_S3)
.build();
var output = storageCreation.execute(input);
Inject the StorageRetrieval
bean in your class and use it to get files.
private final StorageRetrieval storageRetrieval;
Prepare your payload and call the execute
method.
final var input = StorageRetrieval.Input.builder()
.key("path/on/aws/filename.extension")
.type(StorageType.AWS_S3)
.build();
final var output = storageRetrieval.execute(input);
The response will contain the URI of the file stored. You can get it using the following code:
output.getUri();
Inject the StorageRemoval
bean in your class and use it to delete files.
private final StorageRemoval storageRemoval;
Prepare your payload and call the execute
method.
final var input = StorageRemoval.Input.builder()
.key("path/on/aws/filename.extension")
.type(StorageType.AWS_S3)
.build();
storageRemoval.execute(input);