you can use spring-cloud-aws with a s3 capable ResourceLoader:
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aws-context="http://www.springframework.org/schema/cloud/aws/context"
xsi:schemaLocation="http://www.springframework.org/schema/cloud/aws/context http://www.springframework.org/schema/cloud/aws/context/spring-cloud-aws-context.xsd">
<aws-context:context-credentials>
<!-- ... -->
</aws-context:context-credentials>
<aws-context:context-resource-loader/>
</beans>
And inject it into your bean:
public class SimpleResourceLoadingBean {
@Autowired
private ResourceLoader resourceLoader;
public void writeResource() throws IOException {
Resource resource = this.resourceLoader.getResource("s3://myBucket/rootFile.log");
WritableResource writableResource = (WritableResource) resource;
try (OutputStream outputStream = writableResource.getOutputStream()) {
outputStream.write("test".getBytes());
}
}
}
Here you can find the documentation:
http://cloud.spring.io/spring-cloud-static/spring-cloud-aws/1.2.1.RELEASE/#_uploading_files
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…