Reputation: 485
For reference: GET Bucket (List Objects)
When I do a get request on the root bucket it comes back with test/
and test/subdir/
both 0 bytes. Which is correct, there should be 2 folders up there. When I upload a file to test/subdir/file
. The root bucket has an item with the key=test/subdir/file
. test/
and test/subdir/
are still 0 bytes. When I do a get request on test/subdir/
it returns nothing.
What's going on here?
Note: I do not have access to the console.
Upvotes: 0
Views: 60
Reputation: 37832
Greg, this might sound confusing at first, but the truth is that there's no such thing as "a folder" in Amazon S3. I'll explain.
The data structure of S3 is like a flat list of objects -- not like a tree. When you think you have a "file" called puppy.jpg
inside a "folder" called pics
, what you actually have is an object which key is pics/puppy.jpg
. Note that the /
character is not any more special than the .
character, or the p
characters.
You might be thinking, Bruno is nuts, I see folders in the AWS Management Console. True, you see the folders. But they are actually emulated by the GUI.
When you create a folder through the AWS Management Console, what it will actually do is create an object which name is the full path of the "folder", with a trailing slash, and 0 bytes. Just like the test/
object (not "folder") and the test/subdir/
object (not "folder") you mention in your question.
To actually identify and draw "folders", the AWS Management Console (as well as many other S3 browsing tools) is doing is some API magic with the parameters delimiter
and prefix
.
Now, knowing the fact that there's no such thing as a folder, and that they are emulated through the use of those 0-byte, trailing-/ objects, it should be easy to understand why you see the test/
object as a 0-byte object... The same reasoning would explain why you see nothing when you do a GET on a "folder" -- you are actually downloading a 0-byte object!
Finally, as a conclusion, there's no easy way to obtain from S3 the size of "a folder" (they don't exist...). The only way would be for you to list all the objects with that prefix and add their sizes. Or keep an index of your object ("files" and "folders") in some kind of database with more advanced querying capabilities.
Upvotes: 3