You can simple iterate over bucket
objects
and use the with_prefix
method
s3.buckets[YOUR BUCKET NAME].objects.with_prefix('videos/my_videos/college').each.collect(&:key)
#=> ["videos/my_videos/college/myfirst_day.mp4"]
OR use the as_tree
method
s3.buckets[YOUR BUCKET NAME].as_tree(prefix:'videos/my_videos/college').select(&:leaf?).collect(&:key)
#=> ['videos/my_videos/college/myfirst_day.mp4']
Obviously these are fictional since I have no access to your bucket but take a look at ObjectCollection
and Tree
for more methods in the AWSSDK.
There are quite a few methods for bucket traversal available such as Tree
responds to children
which will list both LeafNode
s (File) and BranchNode
s (Directory). BranchNode
s will then also respond to children
so you can make this recursive if needed.
To get the suffix
(e.g. just the filename) you could possibly patch these in.
class LeafNode
def suffix
@member.key.split(delimiter).pop
end
end
class S3Object
def suffix
@key.split("/").pop
end
end
I have not fully tested these in any way but they should work for returning just the file name itself if it is nested inside a branch.