I'm using the AWS SDK v2 for S3 software.amazon.awssdk.s3
. I have a bucket and I'm listing the keys to retrieve the objects. I'm expecting to list object keys, and get something like this:
...
ACTIVE/somefile.jpg
ACTIVE/someotherfile.jpg
...
However, the listing process will also return the root-key so to speak of
ACTIVE/
When I go to run the GetOjbectRequest
for the key ACTIVE/
, it throws an error because you can't retrieve that. So how do I pass to my request that I either only want to list keys of actual objects, or filter my response so that I only have actual objects before GetOjbectRequest
-ing them?
My code currently looks like the following:
List<String> activeRuleKeys = listObjectsV2Responses.stream()
.map(listObjectsV2Response -> listObjectsV2Response.contents())
.flatMap(s3Objects -> s3Objects.stream())
.map(s3Object -> s3Object.key())
.collect(Collectors.toList());
// Error happens below
List<String> ruleSet = activeRuleKeys.stream().map(s -> {
GetObjectRequest build = GetObjectRequest.builder().bucket(bucketName).key(s).build();
String ruleString = this.s3Client.getObject(build, ResponseTransformer.toBytes()).asUtf8String();
return ruleString;
}).collect(Collectors.toList());
Any help is greatly appreciated