use of com.obs.services.ObsClient in project exchange by lmxdawn.
the class HuaWeiObsServiceImpl method createUploadPostParam.
@Override
public HuaWeiObsPostParamRes createUploadPostParam(String suffix) {
StorageSettingVo storageSettingVo = settingService.listToStorageSettingVo();
if (storageSettingVo == null) {
return null;
}
String accessKey = storageSettingVo.getAccessKey();
String secretKey = storageSettingVo.getSecretKey();
String endPoint = storageSettingVo.getUploadUrl();
String bucketName = storageSettingVo.getBucket();
String objectKey = UUIDStringUtils.randomUUID() + "." + suffix;
// URL有效期,3600秒
long expireSeconds = 3600L;
ObsConfiguration config = new ObsConfiguration();
config.setEndPoint(endPoint);
config.setAuthType(AuthTypeEnum.OBS);
ObsClient obsClient = new ObsClient(accessKey, secretKey, config);
Map<String, Object> formParams = new HashMap<>();
String xObsAcl = "public-read";
PostSignatureRequest request = new PostSignatureRequest();
request.setExpires(expireSeconds);
formParams.put("x-obs-acl", xObsAcl);
request.setFormParams(formParams);
PostSignatureResponse response = obsClient.createPostSignature(request);
HuaWeiObsPostParamRes huaWeiObsPostParamRes = new HuaWeiObsPostParamRes();
huaWeiObsPostParamRes.setKey(objectKey);
huaWeiObsPostParamRes.setXObsAcl(xObsAcl);
huaWeiObsPostParamRes.setAccessKeyId(accessKey);
huaWeiObsPostParamRes.setPolicy(response.getPolicy());
huaWeiObsPostParamRes.setSignature(response.getSignature());
String postUrl = "https://" + bucketName + "." + endPoint;
huaWeiObsPostParamRes.setUrl(postUrl);
return huaWeiObsPostParamRes;
}
use of com.obs.services.ObsClient in project exchange by lmxdawn.
the class HuaWeiObsServiceImpl method createUploadPostParamAll.
@Override
public List<HuaWeiObsPostParamRes> createUploadPostParamAll(List<String> suffixs) {
StorageSettingVo storageSettingVo = settingService.listToStorageSettingVo();
if (storageSettingVo == null) {
return null;
}
String accessKey = storageSettingVo.getAccessKey();
String secretKey = storageSettingVo.getSecretKey();
String endPoint = storageSettingVo.getUploadUrl();
String bucketName = storageSettingVo.getBucket();
// URL有效期,3600秒
long expireSeconds = 3600L;
ObsConfiguration config = new ObsConfiguration();
config.setEndPoint(endPoint);
config.setAuthType(AuthTypeEnum.OBS);
ObsClient obsClient = new ObsClient(accessKey, secretKey, config);
Map<String, Object> formParams = new HashMap<>();
String xObsAcl = "public-read";
formParams.put("x-obs-acl", xObsAcl);
List<HuaWeiObsPostParamRes> list = new ArrayList<>();
for (String suffix : suffixs) {
String objectKey = UUIDStringUtils.randomUUID() + "." + suffix;
PostSignatureRequest request = new PostSignatureRequest();
request.setExpires(expireSeconds);
request.setFormParams(formParams);
PostSignatureResponse response = obsClient.createPostSignature(request);
HuaWeiObsPostParamRes huaWeiObsPostParamRes = new HuaWeiObsPostParamRes();
huaWeiObsPostParamRes.setKey(objectKey);
huaWeiObsPostParamRes.setXObsAcl(xObsAcl);
huaWeiObsPostParamRes.setAccessKeyId(accessKey);
huaWeiObsPostParamRes.setPolicy(response.getPolicy());
huaWeiObsPostParamRes.setSignature(response.getSignature());
String postUrl = "https://" + bucketName + "." + endPoint;
huaWeiObsPostParamRes.setUrl(postUrl);
list.add(huaWeiObsPostParamRes);
}
return list;
}
use of com.obs.services.ObsClient in project exchange by lmxdawn.
the class HuaWeiObsServiceImpl method createUploadPutParam.
@Override
public HuaWeiObsPutParamRes createUploadPutParam(String suffix) {
StorageSettingVo storageSettingVo = settingService.listToStorageSettingVo();
if (storageSettingVo == null) {
return null;
}
String accessKey = storageSettingVo.getAccessKey();
String secretKey = storageSettingVo.getSecretKey();
String endPoint = storageSettingVo.getUploadUrl();
String bucketName = storageSettingVo.getBucket();
String objectKey = UUIDStringUtils.randomUUID() + "." + suffix;
// URL有效期,3600秒
long expireSeconds = 3600L;
// 创建ObsClient实例
ObsClient obsClient = new ObsClient(accessKey, secretKey, endPoint);
// 替换成您对应的操作
TemporarySignatureRequest request = new TemporarySignatureRequest(HttpMethodEnum.PUT, expireSeconds);
// 替换为请求本次操作访问的桶名和对象名
request.setBucketName(bucketName);
request.setObjectKey(objectKey);
TemporarySignatureResponse response = obsClient.createTemporarySignature(request);
HuaWeiObsPutParamRes huaWeiObsPutParamRes = new HuaWeiObsPutParamRes();
huaWeiObsPutParamRes.setSignedUrl(response.getSignedUrl());
return huaWeiObsPutParamRes;
}
use of com.obs.services.ObsClient in project simpleFS by shengdingbox.
the class HuaweiCloudOssApiClient method init.
@Override
public HuaweiCloudOssApiClient init(FileProperties fileProperties) {
String huaweiAccessKey = fileProperties.getHuawei().getAccessKey();
String huaweiSecretKey = fileProperties.getOss().getSecretKey();
String huaweiEndpoint = fileProperties.getHuawei().getEndpoint();
String huaweiUrl = fileProperties.getHuawei().getUrl();
String huaweiBucketName = fileProperties.getOss().getBucketName();
if (StringUtils.isNullOrEmpty(huaweiAccessKey) || StringUtils.isNullOrEmpty(huaweiSecretKey) || StringUtils.isNullOrEmpty(huaweiEndpoint)) {
throw new ServiceException("[" + this.storageType + "]尚未配置华为云,文件上传功能暂时不可用!");
}
// 创建ObsClient实例
obsClient = new ObsClient(huaweiAccessKey, huaweiSecretKey, huaweiEndpoint);
this.bucket = huaweiBucketName;
checkDomainUrl(huaweiUrl);
return this;
}
use of com.obs.services.ObsClient in project onex-boot by zhangchaoxu.
the class HuaweiCloudOssService method download.
@Override
public InputStream download(String objectKey) {
ObsClient ossClient = null;
ObsObject ossObject = null;
try {
ossClient = new ObsClient(config.getAccessKeyId(), config.getAccessKeySecret(), config.getEndPoint());
ossObject = ossClient.getObject(config.getBucketName(), objectKey);
return ossObject.getObjectContent();
} catch (ObsException e) {
throw new OnexException(ErrorCode.OSS_UPLOAD_FILE_ERROR, e);
} finally {
// ObsClient在调用ObsClient.close方法关闭后不能再次使用
if (ossClient != null) {
try {
ossClient.close();
} catch (IOException e) {
log.error("huaweicloud obs client close error", e);
}
}
}
}
Aggregations