http://developer.amazonwebservices.com/connect/entry.jspa?externalID=132 よりダウンロード
Eclipseに設置
Amazon Web Service のアカウントから「Access Key ID」と「Secret Access Key」を取得
EclipseでS3Driver.javaに「Access Key ID」と「Secret Access Key」を入力し、実行してみる。
creating bucket OKとなっている。コードでは
27行目
static final String bucketName = awsAccessKeyId.toLowerCase() + "-test-bucket";
となっている。
AWSのコンソールから見ると
アクセスキー+bucket nameで作成されている。
※Response createBucket(bucketName, location) - creates a bucket(Read me)より
[コンソール出力]
----- listing bucket -----
[] ←何もないこと?
ソースでは
59行目
conn.listBucket(bucketName, null, null, null, null).entries
※ListResponse listBucket(bucketName) - lists a bucket's contents
[コンソール出力]
----- bucket location -----
←何も出ていなかった
ソースでは
62行目
conn.getBucketLocation(bucketName).getLocation()
※LocationResponse getBucketLocation(bucketName) - return the location-constraint of this bucket
[コンソール出力]
----- putting object -----
OK
ソースでは
S3Object object = new S3Object("this is a test".getBytes(), null);
Map headers = new TreeMap();
headers.put("Content-Type", Arrays.asList(new String[] { "text/plain" }));
System.out.println(
conn.put(bucketName, keyName, object, headers).connection.getResponseMessage());
つまり内容が"this is a test"のファイル名"test-key"で作成
key-nameは
28行目
static final String keyName = "test-key";
※Response put(bucketName, keyName, object) - writes an object
[コンソール出力]
----- copying object -----
ソースでは
conn.copy( bucketName, keyName, bucketName, copiedKeyName, null );
コピー元とコピー先のペア(bucketName, keyName)
実際にcopy-of-test-key が作成
[コンソール出力]
----- listing bucket -----
[copy-of-test-key, test-key] ←今度はファイルがある
conn.listBucket(bucketName, null, null, null, null).entries
※ListResponse listBucket(bucketName) - lists a bucket's contents
[コンソール出力]
----- getting object -----
this is a test
ソースでは
System.out.println(
new String(conn.get(bucketName, keyName, null).object.data)
);
※GetResponse get(bucketName, keyName) - retrieves an object
[コンソール残り部分]
----- query string auth example -----
Try this url in your web browser (it will only work for 60 seconds)
https://accesskey-test-bucket.s3.amazonaws.com:443/test-key?Signature=fo1Hc7VXoSiH4JwOxPACt%2Bt5zd4%3D&Expires=1283906187&AWSAccessKeyId=accesskey
press enter>
Now try just the url without the query string arguments. It should fail.
https://s3.amazonaws.com:443/accesskey-test-bucket/test-key
press enter> ----- putting object with metadata and public read acl -----
OK
----- anonymous read test -----
You should be able to try this in your browser
https://s3.amazonaws.com:443/accesskey-test-bucket/test-key-public
press enter>
----- path style url example -----
Non-location-constrained buckets can also be specified as part of the url path. (This was the original url style supported by S3.)
Try this url out in your browser (it will only be valid for 60 seconds)
https://s3.amazonaws.com:443/accesskey-test-bucket/test-key?Signature=v3kIpgwWIIWXfsXuFr4hEKhAdiA%3D&Expires=1283909712&AWSAccessKeyId=AKIAIZF2N7LMG6ARJCHA
press enter> ----- getting object's acl -----
----- deleting objects -----
No Content
No Content
No Content
----- listing bucket -----
[]
----- listing all my buckets -----
[accesskey-test-bucket, mizuno, nyonyo, sangi, watanabe-image, watanabe-image2]
----- deleting bucket -----
No Content
0 件のコメント:
コメントを投稿