Reputation: 2443
few things I do know. Folders are not a concept of S3 they are merely a zero byte object with key names that use the '/' as prefixes. Assuming that we call them folders and files for simplicity would make my question easier to phrase.
It is possible to do a s3->get_object_list(..) with prefix ="root/" and get all the files/folders. My problem is this.
Given a list of folders and subfolders for e.g.
root/
root/folder1/
root/folder1/file1.txt
root/folder2/
root/folder3/file2.txt
How can i list only the folders. I was hoping to prevent listing all files (even in response they need not be returned) but get_object_list in php does not current support commonPrefixes ref: http://docs.amazonwebservices.com/AWSSDKforPHP/latest/#m=AmazonS3/get_object_list even though the doc says so the code clearly does not and using the delimiter will actually only return files in the root folder (prefix)
I am wondering if anyone has used any technique post-response or request based to help with such a situation.
I have already tried every combo of prefix,delimiter and marker i could think of. Not so good with PCRE but sure I could use that I only have one level deep folders but I don't know how to construct one for this case. Since my requests were not working I proceeded to accept the response with all files and folders and hopefully sort it out in php... or so I thought
I have tried in post response: dirname() - no use misses out some folders (empty ones), sure I can remove duplicates in array but the problem of missed folder exists pathinfo() - behaves the same way as dirname(), assumes that all paths end with filename. glob - no luck, same as above.
Since I have already wasted half a day on this I am hoping someone has dealt with this and would care to share:
note: I have no problem doing this in python and boto. But this is not python and I have to do this in PHP for this project.
Upvotes: 7
Views: 7453
Reputation: 6935
You've confused get_object_list()
with list_objects()
. See: https://forums.aws.amazon.com/thread.jspa?threadID=106277&tstart=0
Upvotes: 3