Amazon S3 support

AwsS3FileRepository

Implementation that stores all files to Amazon S3. To use this FileRepository, add the following Maven dependency to include the Amazon SDK for S3.

<dependencies>
	<dependency>
           <groupId>com.amazonaws</groupId>
           <artifactId>aws-java-sdk-s3</artifactId>
       </dependency>
</dependencies>

To construct a new AwsS3FileRepository add following method:

@Autowired
public void registerS3Repository( FileRepositoryRegistry registry, FileManager fileManager ) {
 registry.registerRepository(new AwsS3FileRepository(bucketName,amazonAccessKey,amazonAccessSecret,fileManager))
}

The Amazon access keys and secret can be found at https://console.aws.amazon.com/iam. Make sure the corresponding user has permissions to access S3 buckets.

If you want to get a File reference using AwsS3FileRepository#getAsFile, a local copy of the file wil be kept. The provided fileManager is used to create temporary files.

AwsS3FileRepository customization

To configure another region within AWS where your S3 bucket is located, you can provide this amazonRegion in the constuctor. By default the amazonRegion is eu-central-1. Make sure the bucketName refers to a bucket in the given Amazon region.

@Autowired
public void registerS3Repository( FileRepositoryRegistry registry, FileManager fileManager ) {
 registry.registerRepository(new AwsS3FileRepository(bucketName,amazonAccessKey,amazonAccessSecret,fileManager,amazonRegion))
}

If you want other paths to be generated within your S3 bucket, you can pass a PathGenerator instance:

@Autowired
public void registerS3Repository( FileRepositoryRegistry registry, FileManager fileManager ) {
 registry.registerRepository(new AwsS3FileRepository(bucketName,amazonAccessKey,amazonAccessSecret,fileManager,amazonRegion,pathGenerator))
}

By default, no additional paths will be generated and all files will be placed directly in the S3 bucket. Because S3 buckets do not know the concept of "sub-directories" and only keys within buckets, using a pathGenerator is not recommended. However, it can be useful if you want to switch between other implementations of FileRepository later on.