From 8d21118a29f371b70115a9b08aada12b09ccb06f Mon Sep 17 00:00:00 2001 From: wangkang Date: Fri, 1 Dec 2017 15:12:55 +0800 Subject: [PATCH] =?UTF-8?q?=E9=98=BF=E9=87=8C=E4=BA=91OSS=E7=94=9F?= =?UTF-8?q?=E6=88=90=E7=AD=BE=E5=90=8DURL=E5=88=A4=E6=96=ADobjectKey?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E5=AD=98=E5=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../itkk/udf/file/aliyun/oss/OssWarpper.java | 24 +++++++++++++++++++ .../aliyun/oss/web/AliyunOssController.java | 5 ++++ .../aliyun/oss/web/IAliuyinOssController.java | 15 ++++++++++++ 3 files changed, 44 insertions(+) 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); + }