java 使用amazon s3介面訪問本地ceph rgw
ceph官網中使用java訪問rgw s3的程式碼已經不能使用了,
http://docs.ceph.com/docs/kraken/radosgw/s3/java/
折騰了好長時間,在同事的幫助下終於實現了使用java呼叫rgw s3介面,程式碼如下:
public static void main(String[] args) {
String accessKey = "your accessKey";
String secretKey = "your secretKey";
AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
AmazonS3 amazonS3 = AmazonS3ClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(credentials))
.withEndpointConfiguration(
new AwsClientBuilder.EndpointConfiguration(
"your ceph rgw site,like: http://10.0.0.12:8080",
""))
.build();
List<Bucket> listBuckets = amazonS3.listBuckets();
for (Bucket bucket : listBuckets) {
System.out.println(bucket.getName());
}
}
使用過程中需要引入很多包,如有需要可以聯絡本人。