Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/migangqui/spring-aws-s3-api
Spring AWS S3 API for Java and Kotlin
https://github.com/migangqui/spring-aws-s3-api
java kotlin maven spring
Last synced: 8 days ago
JSON representation
Spring AWS S3 API for Java and Kotlin
- Host: GitHub
- URL: https://github.com/migangqui/spring-aws-s3-api
- Owner: migangqui
- License: mit
- Created: 2018-10-14T23:06:46.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-02-01T13:26:06.000Z (almost 2 years ago)
- Last Synced: 2023-07-26T22:02:25.098Z (over 1 year ago)
- Topics: java, kotlin, maven, spring
- Language: Java
- Homepage: https://migangqui.github.io/spring-aws-s3-api/
- Size: 118 KB
- Stars: 5
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Spring AWS S3 API (Java/Kotlin)
We reccomend to use Cloud Storage Spring Api ()
Here we are a Java and a Kotlin API to manage files of AmazonS3 in Spring framework. In order to use it, are necesaries the following steps:
### Add dependency to pom.xml:
If you use Java ():
```xml
com.github.migangqui
spring-aws-s3-java
${currentVersion}```
If you use Kotlin ():
```xml
com.github.migangqui
spring-aws-s3-kotlin
${currentVersion}```
```${currentVersion}``` right now is ```1.1.0```
Both them are in Maven Central.
### Register the following properties in your application.yml:
```yaml
amazon:
s3:
accessKey: [AMAZON_ACCESS_KEY]
secretKey: [AMAZON_SECRET_KEY]
bucket.name: example-bucket-s3
region: [GovCloud("us-gov-west-1"),
US_EAST_1("us-east-1"),
US_WEST_1("us-west-1"),
US_WEST_2("us-west-2"),
EU_WEST_1("eu-west-1"),
EU_CENTRAL_1("eu-central-1"),
AP_SOUTH_1("ap-south-1"),
AP_SOUTHEAST_1("ap-southeast-1"),
AP_SOUTHEAST_2("ap-southeast-2"),
AP_NORTHEAST_1("ap-northeast-1"),
AP_NORTHEAST_2("ap-northeast-2"),
SA_EAST_1("sa-east-1"),
CN_NORTH_1("cn-north-1")]**
```
** Only one and only the string of the region.## Enable async
Add ```@EnableAsync``` annotation in your Spring Application class to enable async upload method.
## File size
To controle max size of files you can upload, set the following properties:
```yaml
spring:
servlet:
multipart:
max-file-size: 128KB
max-request-size: 128KB
```## Localstack support
This library can be tested with Localstack ().
You only have to set the following properties in your application.yml:```yaml
localstack:
enabled: false (by default)
endpoint: http://localhost:4572
region: us-east-1
```In order to run easily Localstack, I have added ```docker-compose.yml``` file to the folder ```localstack```.
You have run the command ```docker-compose up``` to make it work.I hardly recommend install AWS CLI in your local. It helps you to manage the buckets to run the tests with Localstack.
Here you are the documentation to install the version 2:To create a local bucket you must run this command `aws2 --endpoint-url=http://localhost:4572 s3 mb s3://mytestbucket`
To check out if the bucket has been created run this command `aws2 --endpoint-url=http://localhost:4572 s3 ls`
When you create a bucket, you have to add `yourbucketname.localhost` to your hosts local file mapped to `127.0.0.1`.
Here we are the AWS CLI S3 command options:
## How to use
You have to inject ```AmazonS3Service``` as dependency in your Spring component.
The service provide these methods:##### Java
```java
public interface AmazonS3Service {
UploadFileResponse uploadFile(UploadFileRequest request);
Future uploadFileAsync(UploadFileRequest request);GetFileResponse getFile(GetFileRequest request);
DeleteFileResponse deleteFile(DeleteFileRequest request);}
```
##### Kotlin
```kotlin
interface AmazonS3Service {
fun uploadFile(request: UploadFileRequest): UploadFileResponse
fun uploadFileAsync(request: UploadFileRequest): Futurefun getFile(request: GetFileRequest): GetFileResponse
fun deleteFile(request: DeleteFileRequest): DeleteFileResponse
}
```## License
This project is licensed under the MIT License - see the LICENSE file for details
## Improvements
### v1.1.0
* Improve configuration
* Not component scan necessary
* Refactor code
* Chose bucket name dynamically
* Beans to manage all request and responses
* AWS S3 File access configuration (Private by default)## Next improvements
I'm very pleased to receive suggestions.