mirror of
https://gitee.com/wangkang/udf.git
synced 2026-10-28 09:23:44 +00:00
添加阿里云OSS方法,指定路径前缀返回Object清单
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package org.itkk.udf.core.domain.aliyun.oss;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import org.hibernate.validator.constraints.NotBlank;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* OssListParam
|
||||
*/
|
||||
@ApiModel(description = "阿里云oss对象信息")
|
||||
@Data
|
||||
public class OssListParam implements Serializable {
|
||||
|
||||
/**
|
||||
* 描述 : ID
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* code
|
||||
*/
|
||||
@ApiModelProperty(value = "阿里云oss的配置代码", required = true, dataType = "string")
|
||||
@NotBlank(message = "阿里云oss的配置代码不能为空")
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* keyPrefix
|
||||
*/
|
||||
@ApiModelProperty(value = "阿里云oss的的对象key前缀", required = true, dataType = "string")
|
||||
@NotBlank(message = "阿里云oss的的对象key前缀不能为空")
|
||||
private String keyPrefix;
|
||||
}
|
||||
+64
-5
@@ -2,6 +2,9 @@ package org.itkk.udf.file.aliyun.oss.api;
|
||||
|
||||
import com.aliyun.oss.OSSClient;
|
||||
import com.aliyun.oss.common.utils.BinaryUtil;
|
||||
import com.aliyun.oss.model.ListObjectsRequest;
|
||||
import com.aliyun.oss.model.OSSObjectSummary;
|
||||
import com.aliyun.oss.model.ObjectListing;
|
||||
import com.aliyun.oss.model.PolicyConditions;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.itkk.udf.core.ApplicationConfig;
|
||||
@@ -16,7 +19,9 @@ import java.io.File;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URL;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* OssWarpper
|
||||
@@ -24,6 +29,21 @@ import java.util.Date;
|
||||
@Component
|
||||
public class OssWarpper {
|
||||
|
||||
/**
|
||||
* MSG_1
|
||||
*/
|
||||
private static final String MSG_1 = "aliyun oss code:";
|
||||
|
||||
/**
|
||||
* MSG_2
|
||||
*/
|
||||
private static final String MSG_2 = "未定义";
|
||||
|
||||
/**
|
||||
* MAX_KEYS
|
||||
*/
|
||||
private static final int MAX_KEYS = 100;
|
||||
|
||||
/**
|
||||
* NUM_1000
|
||||
*/
|
||||
@@ -46,6 +66,45 @@ public class OssWarpper {
|
||||
@Autowired
|
||||
private AliyunOssProperties aliyunOssProperties;
|
||||
|
||||
/**
|
||||
* list
|
||||
*
|
||||
* @param code code
|
||||
* @param keyPrefix keyPrefix
|
||||
* @return List<OSSObjectSummary>
|
||||
*/
|
||||
public List<OSSObjectSummary> list(String code, String keyPrefix) {
|
||||
//返回值
|
||||
List<OSSObjectSummary> result = new ArrayList<>();
|
||||
//判空
|
||||
if (!aliyunOssProperties.getAuth().containsKey(code) || !aliyunOssProperties.getPath().containsKey(code)) {
|
||||
throw new ParameterValidException(MSG_1 + code + MSG_2, null); //NOSONAR
|
||||
}
|
||||
//获得认证信息 和 路径信息
|
||||
AliyunOssAccessMeta auth = aliyunOssProperties.getAuth().get(code);
|
||||
AliyunOssPathMeta path = aliyunOssProperties.getPath().get(code);
|
||||
//实例化oss对象
|
||||
OSSClient client = new OSSClient(auth.getEndPoint(), auth.getAccessId(), auth.getAccessKey());
|
||||
try {
|
||||
//循环获取列表
|
||||
String nextMarker = null;
|
||||
ObjectListing objectListing;
|
||||
do {
|
||||
objectListing = client.listObjects(new ListObjectsRequest(path.getBucketName())
|
||||
.withMarker(nextMarker)
|
||||
.withPrefix(keyPrefix)
|
||||
.withMaxKeys(MAX_KEYS)
|
||||
);
|
||||
result.addAll(objectListing.getObjectSummaries());
|
||||
nextMarker = objectListing.getNextMarker();
|
||||
} while (objectListing.isTruncated());
|
||||
//返回
|
||||
return result;
|
||||
} finally {
|
||||
client.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* getPolicy
|
||||
*
|
||||
@@ -56,7 +115,7 @@ public class OssWarpper {
|
||||
public PolicyResult getPolicy(String code) throws UnsupportedEncodingException {
|
||||
//判空
|
||||
if (!aliyunOssProperties.getAuth().containsKey(code) || !aliyunOssProperties.getPath().containsKey(code)) {
|
||||
throw new ParameterValidException("aliyun oss code:" + code + "未定义", null); //NOSONAR
|
||||
throw new ParameterValidException(MSG_1 + code + MSG_2, null); //NOSONAR
|
||||
}
|
||||
//获得认证信息 和 路径信息
|
||||
AliyunOssAccessMeta auth = aliyunOssProperties.getAuth().get(code);
|
||||
@@ -98,7 +157,7 @@ public class OssWarpper {
|
||||
public String getPresignedUrl(String code, String objectKey) {
|
||||
//判空
|
||||
if (!aliyunOssProperties.getAuth().containsKey(code) || !aliyunOssProperties.getPath().containsKey(code)) {
|
||||
throw new ParameterValidException("aliyun oss code:" + code + "未定义", null);
|
||||
throw new ParameterValidException(MSG_1 + code + MSG_2, null);
|
||||
}
|
||||
//获得认证信息 和 路径信息
|
||||
AliyunOssAccessMeta auth = aliyunOssProperties.getAuth().get(code);
|
||||
@@ -137,7 +196,7 @@ public class OssWarpper {
|
||||
public void delete(String code, String objectKey) {
|
||||
//判空
|
||||
if (!aliyunOssProperties.getAuth().containsKey(code) || !aliyunOssProperties.getPath().containsKey(code)) {
|
||||
throw new ParameterValidException("aliyun oss code:" + code + "未定义", null);
|
||||
throw new ParameterValidException(MSG_1 + code + MSG_2, null);
|
||||
}
|
||||
//获得认证信息 和 路径信息
|
||||
AliyunOssAccessMeta auth = aliyunOssProperties.getAuth().get(code);
|
||||
@@ -164,7 +223,7 @@ public class OssWarpper {
|
||||
public boolean checkExist(String code, String objectKey) {
|
||||
//判空
|
||||
if (!aliyunOssProperties.getAuth().containsKey(code) || !aliyunOssProperties.getPath().containsKey(code)) {
|
||||
throw new ParameterValidException("aliyun oss code:" + code + "未定义", null);
|
||||
throw new ParameterValidException(MSG_1 + code + MSG_2, null);
|
||||
}
|
||||
//获得认证信息 和 路径信息
|
||||
AliyunOssAccessMeta auth = aliyunOssProperties.getAuth().get(code);
|
||||
@@ -188,7 +247,7 @@ public class OssWarpper {
|
||||
public String uploadFile(String code, File file) {
|
||||
//判空
|
||||
if (!aliyunOssProperties.getAuth().containsKey(code) || !aliyunOssProperties.getPath().containsKey(code)) {
|
||||
throw new ParameterValidException("aliyun oss code:" + code + "未定义", null);
|
||||
throw new ParameterValidException(MSG_1 + code + MSG_2, null);
|
||||
}
|
||||
//获得认证信息 和 路径信息
|
||||
AliyunOssAccessMeta auth = aliyunOssProperties.getAuth().get(code);
|
||||
|
||||
+9
-1
@@ -6,12 +6,14 @@
|
||||
*/
|
||||
package org.itkk.udf.file.aliyun.oss.web;
|
||||
|
||||
import com.aliyun.oss.model.OSSObjectSummary;
|
||||
import org.itkk.udf.core.RestResponse;
|
||||
import org.itkk.udf.core.domain.aliyun.oss.OssListParam;
|
||||
import org.itkk.udf.core.domain.aliyun.oss.OssParam;
|
||||
import org.itkk.udf.file.aliyun.oss.api.OssWarpper;
|
||||
import org.itkk.udf.file.aliyun.oss.api.domain.PolicyResult;
|
||||
import org.itkk.udf.file.aliyun.oss.api.download.DownloadInfo;
|
||||
import org.itkk.udf.file.aliyun.oss.api.download.DownLoadProcessService;
|
||||
import org.itkk.udf.file.aliyun.oss.api.download.DownloadInfo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
@@ -19,6 +21,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 描述 : AliyunOssController
|
||||
@@ -40,6 +43,11 @@ public class AliyunOssController implements IAliuyinOssController {
|
||||
@Autowired
|
||||
private DownLoadProcessService downLoadProcessService;
|
||||
|
||||
@Override
|
||||
public RestResponse<List<OSSObjectSummary>> list(@RequestBody @Valid OssListParam ossListParam) {
|
||||
return new RestResponse<>(ossWarpper.list(ossListParam.getCode(), ossListParam.getKeyPrefix()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public RestResponse<PolicyResult> policy(@PathVariable String code) throws IOException {
|
||||
return new RestResponse<>(ossWarpper.getPolicy(code));
|
||||
|
||||
+18
@@ -6,11 +6,13 @@
|
||||
*/
|
||||
package org.itkk.udf.file.aliyun.oss.web;
|
||||
|
||||
import com.aliyun.oss.model.OSSObjectSummary;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.itkk.udf.core.RestResponse;
|
||||
import org.itkk.udf.core.domain.aliyun.oss.OssListParam;
|
||||
import org.itkk.udf.core.domain.aliyun.oss.OssParam;
|
||||
import org.itkk.udf.file.aliyun.oss.api.domain.PolicyResult;
|
||||
import org.itkk.udf.file.aliyun.oss.api.download.DownloadInfo;
|
||||
@@ -21,6 +23,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 描述 : IAliuyinOssController
|
||||
@@ -32,6 +35,21 @@ import java.io.IOException;
|
||||
@RequestMapping(value = "/service/aliyun/oss")
|
||||
public interface IAliuyinOssController {
|
||||
|
||||
/**
|
||||
* 描述 : 根据key前缀获得阿里云oss的对象列表(公网)
|
||||
*
|
||||
* @param ossListParam ossListParam
|
||||
* @return 结果
|
||||
*/
|
||||
@ApiOperation(value = "FILE_ALIYUN_OSS_LIST", notes = "根据key前缀获得阿里云oss的对象列表(公网)")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(paramType = "header", name = "rmsApplicationName", value = "rms应用名称", required = true, dataType = "string"),
|
||||
@ApiImplicitParam(paramType = "header", name = "rmsSign", value = "rms认证秘钥", required = true, dataType = "string"),
|
||||
@ApiImplicitParam(paramType = "header", name = "rmsServiceCode", value = "rms接口编号", required = true, dataType = "string")
|
||||
})
|
||||
@RequestMapping(value = "list", method = RequestMethod.POST)
|
||||
RestResponse<List<OSSObjectSummary>> list(@RequestBody @Valid OssListParam ossListParam);
|
||||
|
||||
/**
|
||||
* 描述 : 获得阿里云OSS的policy(公网)
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user