Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does ListObjects return the prefix as a separate object in the array?

Tags:

amazon-s3

I uploaded 4 objects to S3. The object keys are as follows:

4eec12eb0a588620cccad16f/MumDad70s.jpg
4eec12eb0a588620cccad16f/NathanI-1.jpg
4eec12eb0a588620cccad16f/ProfilePic.png
4eec12eb0a588620cccad16f/nathan-orange.jpg

My code to request the objects is:

var req = new ListObjectsRequest()
    .WithBucketName(BucketName)
    .WithPrefix(jobid + "/")
    .WithDelimiter("/");
var objs = _s3Client.ListObjects(req);

In the response, even though the prefix is not actually its own object, but rather just a string prepended to the key of the actual objects, I get the following 5 objects returned:

4eec12eb0a588620cccad16f/
4eec12eb0a588620cccad16f/MumDad70s.jpg
4eec12eb0a588620cccad16f/NathanI-1.jpg
4eec12eb0a588620cccad16f/ProfilePic.png
4eec12eb0a588620cccad16f/nathan-orange.jpg

Why is the prefix being returned as though it were a unique object? How do I just return the files with the specified prefix without having to post-filter the list to get rid of the prefix object?

like image 851
Nathan Ridley Avatar asked Oct 09 '22 05:10

Nathan Ridley


1 Answers

As per here (and yes, I realize you're probably not asking for the Java documentation): http://docs.amazonwebservices.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/AmazonS3.html#listObjects%28com.amazonaws.services.s3.model.ListObjectsRequest%29

It states:

If calling listObjects with a prefix value of "foo/" and a delimiter value of "/" on this bucket, an ObjectListing is returned that contains one key ("foo/boo") and one entry in the common prefixes list ("foo/bar/"). To see deeper into the virtual hierarchy, make another call to listObjects setting the prefix parameter to any interesting common prefix to list the individual keys under that prefix.

Emphasis mine. It looks like this is actually the intended functionality - to return the prefix common to all the keys.

like image 194
AASoft Avatar answered Oct 13 '22 00:10

AASoft