阿里云OSS生成签名URL判断objectKey是否存在

This commit is contained in:
wangkang
2017-12-01 15:12:55 +08:00
parent 413a0952ed
commit 8d21118a29
3 changed files with 44 additions and 0 deletions
@@ -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();
}
}
}
@@ -47,4 +47,9 @@ public class AliyunOssController implements IAliuyinOssController {
ossWarpper.delete(ossParam.getCode(), ossParam.getObjectKey());
return new RestResponse<>();
}
@Override
public RestResponse<Boolean> checkExist(@RequestBody @Valid OssParam ossParam) {
return new RestResponse<>(ossWarpper.checkExist(ossParam.getCode(), ossParam.getObjectKey()));
}
}
@@ -78,4 +78,19 @@ public interface IAliuyinOssController {
@RequestMapping(value = "delete", method = RequestMethod.PUT)
RestResponse<String> 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<Boolean> checkExist(@RequestBody @Valid OssParam ossParam);
}