wtorek, lipca 12, 2016

Ceph S3 API SignatureDoesNotMatch

Use Amazon SDK Client (https://sdk-for-java.amazonwebservices.com/latest/aws-java-sdk.zip) and following Java code:

String accessKey = "1";
String secretKey = "2";
String endpoint = "http://localhost:8080";
String bucket = "UPPERCASE";

SignerFactory.registerSigner("S3SignerType", S3Signer.class);
BasicAWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
ClientConfiguration clientConfig = new ClientConfiguration();
clientConfig.setSignerOverride("S3SignerType");
clientConfig.setProtocol(Protocol.HTTP);

AmazonS3Client conn = new AmazonS3Client(credentials, clientConfig);
conn.setEndpoint(endpoint);
InMemoryRegionImpl region = new  InMemoryRegionImpl("ceph", "localhost");
region.addEndpoint("s3", endpoint);
conn.setRegion(new com.amazonaws.regions.Region(region));

System.out.println(conn.listBuckets().get(0));

byte[] bytes = "Hello World!".getBytes();
ByteArrayInputStream input = new ByteArrayInputStream(bytes);
try {
ObjectMetadata md = new ObjectMetadata();
md.setContentLength(bytes.length);
md.setHeader("x-amz-acl", "public-read");
PutObjectRequest por = new PutObjectRequest(bucket, "plik.txt", input, md);
PutObjectResult res = conn.putObject(por);
System.out.println(res);
}
catch (AmazonS3Exception s3e) {
s3e.printStackTrace();
}

0 komentarze: