I have fetched all the common prefix from S3 and now i want to store these common prefix in fixed size array of String, so i tried to loop over the List and tried to cat the element into Stirng but it doesnt allow me to do the same.
String bucketName = s3BucketDetails.getBucketName();
String bucketPath = s3BucketDetails.getBucketPrefix();
VehicleHeaderImage vehicleHeaderImage = null;
List<S3Object> objList = new ArrayList<>();
S3ResponseMessage response = null;
String[] array;
int index = 0;
try {
List<CommonPrefix> allKeysInDesiredBucket = listAllKeysInABucket(bucketName, bucketPath);
array = new String[allKeysInDesiredBucket.size()];
for (Object value : allKeysInDesiredBucket) {
array[index] = (String) value;
index ;
}
// for (int i = 0; i <= array.length - 1; i ) {
objList = s3Service.getBucketObjects(bucketName, array[1]);
// }
if it is not possible then how do I fetch the common prefix from List<CommonPrefix>
CodePudding user response:
There is a public method on the CommonPrefix
object called prefix()
which returns a String
— that might be what you are looking for.
S3 sdk reference: https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/s3/model/CommonPrefix.html