OssFileUtil.java
1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package com.vion.utils;
import com.aliyun.oss.OSSClient;
import com.aliyun.oss.model.ListObjectsRequest;
import com.aliyun.oss.model.ObjectListing;
/**
* @author 谢明辉
* @createDate 2018-11-6
* @description
*/
public class OssFileUtil {
/**
* @param prefix 路径前缀,例如,picture/face/20181010
* @param bucketName bucketName
* @param maxKeys 列出的最大文件数量,如果为null,默认100,最大为1000
* @param delimiter 是否使用分割符
* @param ossClient ossClient实例
* @return com.aliyun.oss.model.ObjectListing
* @createDate 2018-11-6
* @description 列举指定目录下的所有文件
*/
public ListObjectsRequest getFilesInPrefix(String bucketName, String prefix, OSSClient ossClient, Integer maxKeys, boolean delimiter) {
ListObjectsRequest listObjectsRequest = new ListObjectsRequest(bucketName);
if (maxKeys != null) {
listObjectsRequest.setMaxKeys(maxKeys);
}
if (delimiter) {
listObjectsRequest.setDelimiter("/");
}
listObjectsRequest.setPrefix(prefix);
return listObjectsRequest;
}
}