|
@@ -301,4 +301,31 @@ public class S3FileService extends AbstractFYunFileService {
|
|
|
.withMethod(HttpMethod.PUT).withExpiration(expiration);
|
|
|
return s3.generatePresignedUrl(generatePresignedUrlRequest);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public long getSubFileNums(String bucket, String url) {
|
|
|
+ long totalFileNums = 0;
|
|
|
+ try {
|
|
|
+ boolean flag = true;
|
|
|
+ String nextMaker = null;
|
|
|
+ ListObjectsRequest listObjectsRequest = new ListObjectsRequest();
|
|
|
+ listObjectsRequest.setBucketName(bucket);
|
|
|
+ listObjectsRequest.setPrefix(url);
|
|
|
+ listObjectsRequest.setMaxKeys(200);
|
|
|
+
|
|
|
+ do {
|
|
|
+ listObjectsRequest.setMarker(nextMaker);
|
|
|
+ ObjectListing objectListing = s3.listObjects(listObjectsRequest);
|
|
|
+ List<S3ObjectSummary> objectSummaries = objectListing.getObjectSummaries();
|
|
|
+ List<String> collect = objectSummaries.stream().map(S3ObjectSummary::getKey).collect(Collectors.toList());
|
|
|
+ totalFileNums = totalFileNums + collect.size();
|
|
|
+ nextMaker = objectListing.getNextMarker();
|
|
|
+ flag = objectListing.isTruncated();
|
|
|
+ } while (flag);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("获取文件数量失败,path=" + url, e);
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return totalFileNums;
|
|
|
+ }
|
|
|
}
|