[英]class software.amazon.awssdk.services.s3.model.CommonPrefix cannot be cast to class java.lang.String
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.我已经从 S3 中获取了所有公共前缀,现在我想将这些公共前缀存储在固定大小的字符串数组中,所以我尝试遍历列表并尝试将元素放入 Stirng,但它不允许我做同样的事情.
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>
如果不可能,那么如何从List<CommonPrefix>
中获取公共前缀
There is a public method on the CommonPrefix
object called prefix()
which returns a String
— that might be what you are looking for. CommonPrefix
object 上有一个名为prefix()
的公共方法,它返回一个String
——这可能就是您要查找的内容。
S3 sdk reference: https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/s3/model/CommonPrefix.html S3 sdk 参考: https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/s3/model/CommonPrefix.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.