mardi 28 avril 2015

AWS get all objects inside of folder in S3

I would like to get all the URLs of objects stored in a folder. I will only have one level of folders so I am not concerned with nested folders. I have read the PHP client API (http://ift.tt/1J7FIJK) for S3 but can't seem to find a way to accomplish this.

I found this code from StackOverflow to get the size of contents:

List<Bucket> buckets = s3.listBuckets();
long totalSize  = 0;
int  totalItems = 0;
for (Bucket bucket : buckets)
{
    ObjectListing objects = s3.listObjects(bucket.getName());
    do {
        for (S3ObjectSummary objectSummary : objects.getObjectSummaries()) {
            totalSize += objectSummary.getSize();
            totalItems++;
        }
        objects = s3.listNextBatchOfObjects(objects);
    } while (objects.isTruncated());
    System.out.println("You have " + buckets.size() + " Amazon S3 bucket(s), " +
                    "containing " + totalItems + " objects with a total size of " + totalSize + " bytes.");
}

Which is close to something I want, except I do not want all the items in a bucket, except I want all the items in a certain bucket's folder. My second question is how much would I need to spend to accomplish this as there doesn't seem to be an get/put commands being used?




Aucun commentaire:

Enregistrer un commentaire