Quantcast
Channel: Active questions tagged ruby - Stack Overflow
Viewing all articles
Browse latest Browse all 4619

S3 Ruby SDK List Only Objects Directly under a prefix?

$
0
0

I'm trying to get a single level of objects under a prefix in an S3 bucket. There are a LARGE number of objects in the bucket so I want to iterate over each folder under a specific prefix. Here's my code so far:

require 'aws-sdk'region = 'us-west-1'bucket_name = 'my-example-bucket'prefix = 'test1'delimiter = '/'s3_client = Aws::S3::Client.new(region: region)resp = s3_client.list_objects_v2(bucket: bucket_name, prefix: prefix, delimiter: prefix + delimiter)obj_list = []resp.contents.each do |c|  p c  breakend

When I run this I get a single object that's 4 levels deep inside of my prefix.

There are 243 folders under the prefix. I only want these 243 and nothing else.

How do I do this?


Viewing all articles
Browse latest Browse all 4619

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>