Adding S3 metadata using jets3t

Posted by billintx on Stack Overflow See other posts from Stack Overflow or by billintx
Published on 2010-03-24T15:39:28Z Indexed on 2010/03/24 15:43 UTC
Read the original article Hit count: 423

Filed under:
|
|

I'm just starting to use the jets3t API for S3, using version 0.7.2

I can't seem to save metadata with the S3Objects I'm creating.

What am I doing wrong?

The object is successfully saved when I putObject, but I don't see the metadata after I get the object.

        S3Service s3Service = new RestS3Service(awsCredentials);

        S3Bucket bucket = s3Service.getBucket(BUCKET_NAME);
        String key = "/1783c05a/p1";
        String data = "This is test data at key " + key;

        S3Object object = new S3Object(key,data);

        object.addMetadata("color", "green");

        for (Iterator iterator = object.getMetadataMap().keySet()
                .iterator(); iterator.hasNext();) {
            String type = (String) iterator.next();
            System.out.println(type + "=="
                    + object.getMetadataMap().get(type));
        }

        s3Service.putObject(bucket, object);

        S3Object retreivedObject = s3Service.getObject(bucket, key);

        for (Iterator iterator = object.getMetadataMap().keySet()
                .iterator(); iterator.hasNext();) {
            String type = (String) iterator.next();
            System.out.println(type + "=="
                    + object.getMetadataMap().get(type));
        }

Here's the output before putObject

Content-Length==37
color==green
Content-MD5==AOdkk23V6k+rLEV03171UA==
Content-Type==text/plain; charset=utf-8
md5-hash==00e764936dd5ea4fab2c4574df5ef550

Here's the output after putObject/getObject

Content-Length==37
ETag=="00e764936dd5ea4fab2c4574df5ef550"
request-id==9ED1633672C0BAE9
Date==Wed Mar 24 09:51:44 CDT 2010
Content-MD5==AOdkk23V6k+rLEV03171UA==
Content-Type==text/plain; charset=utf-8

© Stack Overflow or respective owner

Related posts about amazon-s3

Related posts about jets3t