To store files to S3, the best way is to use S3 SDK. To use the API of the SDK, we will need to create an S3 client that can be reused between multiple requests.
The following is how we initialize the S3FileStorage, our FileStorage implementation based on S3:
...@Component("s3FileStorage")public class S3FileStorage extends AbstractBaseFileStorage { private Environment environment; private String rootTempPath; private AmazonS3 s3; public S3FileStorage(Environment environment, @Value("${app.file-storage.temp-folder}") String rootTempPath) { this.environment = environment; this.rootTempPath = rootTempPath; if ("s3FileStorage".equals(environment.getProperty("app.file- storage.active"))) { this.s3 = initS3Client(); } } ... ...