亚马逊s3的使用方法
在Java世界中,有几种很好的方法可以将内容上传到S3存储桶-在本文中,我们将研究jclouds库为此提供的功能。 要使用jclouds –特别是本文中讨论的API,应将此简单的Maven依赖项添加到项目的pom中:
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-allblobstore</artifactId>
<version>1.5.9</version>
</dependency>
1.上载到Amazon S3
为了访问这些API中的任何一个,第一步是创建一个BlobStoreContext :
BlobStoreContext context =
ContextBuilder.newBuilder('aws-s3').credentials(identity, credentials)
.buildView(BlobStoreContext.class);
这表示常规键值存储服务(例如Amazon S3)的切入点,但不仅限于此。 对于仅用于S3的更具体的实现,可以类似地创建上下文:
BlobStoreContext context =
ContextBuilder.newBuilder('aws-s3').credentials(identity, credentials)
.buildView(S3BlobStoreContext.class);
更具体地说:
BlobStoreContext context =
ContextBuilder.newBuilder('aws-s3').credentials(identity, credentials)
.buildView(AWSS3BlobStoreContext.class);
当不再需要经过身份验证的上下文时,需要关闭