diff --git a/udf-starter-file-aliyun-oss/src/main/java/org/itkk/udf/file/aliyun/oss/OssWarpper.java b/udf-starter-file-aliyun-oss/src/main/java/org/itkk/udf/file/aliyun/oss/OssWarpper.java index 76641fe..4a5525e 100644 --- a/udf-starter-file-aliyun-oss/src/main/java/org/itkk/udf/file/aliyun/oss/OssWarpper.java +++ b/udf-starter-file-aliyun-oss/src/main/java/org/itkk/udf/file/aliyun/oss/OssWarpper.java @@ -152,4 +152,28 @@ public class OssWarpper { } } + /** + * 判断文件是否存在 + * + * @param code code + * @param objectKey objectKey + * @return boolean + */ + public boolean checkExist(String code, String objectKey) { + //判空 + if (!aliyunOssProperties.getAuth().containsKey(code) || !aliyunOssProperties.getPath().containsKey(code)) { + throw new ParameterValidException("aliyun oss code:" + code + "未定义", null); + } + //获得认证信息 和 路径信息 + AliyunOssAccessMeta auth = aliyunOssProperties.getAuth().get(code); + AliyunOssPathMeta path = aliyunOssProperties.getPath().get(code); + //实例化oss对象 + OSSClient client = new OSSClient(auth.getEndPoint(), auth.getAccessId(), auth.getAccessKey()); + try { + return client.doesObjectExist(path.getBucketName(), objectKey); + } finally { + client.shutdown(); + } + } + } diff --git a/udf-starter-file-aliyun-oss/src/main/java/org/itkk/udf/file/aliyun/oss/web/AliyunOssController.java b/udf-starter-file-aliyun-oss/src/main/java/org/itkk/udf/file/aliyun/oss/web/AliyunOssController.java index a0976b6..858060e 100644 --- a/udf-starter-file-aliyun-oss/src/main/java/org/itkk/udf/file/aliyun/oss/web/AliyunOssController.java +++ b/udf-starter-file-aliyun-oss/src/main/java/org/itkk/udf/file/aliyun/oss/web/AliyunOssController.java @@ -47,4 +47,9 @@ public class AliyunOssController implements IAliuyinOssController { ossWarpper.delete(ossParam.getCode(), ossParam.getObjectKey()); return new RestResponse<>(); } + + @Override + public RestResponse checkExist(@RequestBody @Valid OssParam ossParam) { + return new RestResponse<>(ossWarpper.checkExist(ossParam.getCode(), ossParam.getObjectKey())); + } } diff --git a/udf-starter-file-aliyun-oss/src/main/java/org/itkk/udf/file/aliyun/oss/web/IAliuyinOssController.java b/udf-starter-file-aliyun-oss/src/main/java/org/itkk/udf/file/aliyun/oss/web/IAliuyinOssController.java index 97439b4..314d650 100644 --- a/udf-starter-file-aliyun-oss/src/main/java/org/itkk/udf/file/aliyun/oss/web/IAliuyinOssController.java +++ b/udf-starter-file-aliyun-oss/src/main/java/org/itkk/udf/file/aliyun/oss/web/IAliuyinOssController.java @@ -78,4 +78,19 @@ public interface IAliuyinOssController { @RequestMapping(value = "delete", method = RequestMethod.PUT) RestResponse delete(@RequestBody @Valid OssParam ossParam); + /** + * 判断阿里云OSS对象是否存在 + * + * @param ossParam ossParam + * @return 结果 + */ + @ApiOperation(value = "FILE_ALIYUN_OSS_CHECK_EXIST", notes = "判断阿里云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 = "check/exist", method = RequestMethod.POST) + RestResponse checkExist(@RequestBody @Valid OssParam ossParam); + }