2016年11月24日 星期四
[Android][AWS] How to iterate all AWS S3 bucket access right 如何列舉 AWS S3 的所有 bucket
AWSCredentials creden = new BasicAWSCredentials("AKIAIIZCDEMXYJP5G3RA", "oBy8PZKgxAMKxw9sEhmvjfZ0seHNvE2SBLgyWN8i");
AmazonS3Client s3Client = new AmazonS3Client(creden);
List<Bucket> buckets = s3Client.listBuckets();
for (Bucket bucket : buckets) {
// Log.d("charles", bucket.getName());
try {
ListObjectsRequest lor = new ListObjectsRequest()
.withBucketName(bucket.getName());
ObjectListing objectListing = s3Client.listObjects(lor);
for (S3ObjectSummary summary: objectListing.getObjectSummaries()) {
// Log.d("charles", summary.getKey());
}
Log.d("charles", bucket.getName() + " : granted");
} catch (AmazonS3Exception e) {
Log.d("charles", bucket.getName() + " : AccessDenied");
}
}
[Android][AWS] How to iterate all AWS S3 bucket access right 如何列舉 AWS S3 的所有 bucket
AWSCredentials creden = new BasicAWSCredentials("AKIAIIZCDEMXYJP5G3RA", "oBy8PZKgxAMKxw9sEhmvjfZ0seHNvE2SBLgyWN8i");
AmazonS3Client s3Client = new AmazonS3Client(creden);
List<Bucket> buckets = s3Client.listBuckets();
for (Bucket bucket : buckets) {
// Log.d("charles", bucket.getName());
try {
ListObjectsRequest lor = new ListObjectsRequest()
.withBucketName(bucket.getName());
ObjectListing objectListing = s3Client.listObjects(lor);
for (S3ObjectSummary summary: objectListing.getObjectSummaries()) {
// Log.d("charles", summary.getKey());
}
Log.d("charles", bucket.getName() + " : granted");
} catch (AmazonS3Exception e) {
Log.d("charles", bucket.getName() + " : AccessDenied");
}
}
2016年11月22日 星期二
[Android][AWS] How to connent to AWS S3 get data
get Keys form AWS S3
AmazonS3 s3 = new AmazonS3Client(CRED);
ListObjectsRequest lor = new ListObjectsRequest()
.withBucketName("myBucket")
.withPrefix("code/");
ObjectListing objectListing = s3.listObjects(lor);
for (S3ObjectSummary summary: objectListing.getObjectSummaries()) {
System.out.println(summary.getKey());
}
AWSCredentials creden=new BasicAWSCredentials(accessKey,secretKey);
AmazonS3Client s3Client=new AmazonS3Client(creden);
S3Object object = s3Client.getObject(new GetObjectRequest(
"BucketName", "keyName"));
BufferedReader reader = new BufferedReader(new InputStreamReader(
object.getObjectContent()));
Writer writer = new OutputStreamWriter(new FileOutputStream(file));
while (true) {
String line = reader.readLine();
if (line == null)
break;
writer.write(line + "\n");
}
writer.flush();
writer.close();
reader.close();
http://stackoverflow.com/
訂閱:
文章 (Atom)