Search in sources :

Example 6 with ObsClient

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;
}
Also used : StorageSettingVo(com.lmxdawn.other.vo.StorageSettingVo) ObsConfiguration(com.obs.services.ObsConfiguration) HashMap(java.util.HashMap) HuaWeiObsPostParamRes(com.lmxdawn.other.res.HuaWeiObsPostParamRes) ObsClient(com.obs.services.ObsClient)

Example 7 with ObsClient

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;
}
Also used : StorageSettingVo(com.lmxdawn.other.vo.StorageSettingVo) ObsConfiguration(com.obs.services.ObsConfiguration) HashMap(java.util.HashMap) HuaWeiObsPostParamRes(com.lmxdawn.other.res.HuaWeiObsPostParamRes) ArrayList(java.util.ArrayList) ObsClient(com.obs.services.ObsClient)

Example 8 with ObsClient

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;
}
Also used : StorageSettingVo(com.lmxdawn.other.vo.StorageSettingVo) HuaWeiObsPutParamRes(com.lmxdawn.other.res.HuaWeiObsPutParamRes) ObsClient(com.obs.services.ObsClient)

Example 9 with ObsClient

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;
}
Also used : ServiceException(com.zhouzifei.tool.common.ServiceException) ObsClient(com.obs.services.ObsClient)

Example 10 with ObsClient

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);
            }
        }
    }
}
Also used : OnexException(com.nb6868.onex.common.exception.OnexException) ObsException(com.obs.services.exception.ObsException) ObsObject(com.obs.services.model.ObsObject) ObsClient(com.obs.services.ObsClient)

Aggregations

ObsClient (com.obs.services.ObsClient)12 StorageSettingVo (com.lmxdawn.other.vo.StorageSettingVo)4 IOException (java.io.IOException)4 FileOperationException (run.halo.app.exception.FileOperationException)4 HuaWeiObsPostParamRes (com.lmxdawn.other.res.HuaWeiObsPostParamRes)2 HuaWeiObsPutParamRes (com.lmxdawn.other.res.HuaWeiObsPutParamRes)2 OnexException (com.nb6868.onex.common.exception.OnexException)2 ObsConfiguration (com.obs.services.ObsConfiguration)2 ObsException (com.obs.services.exception.ObsException)2 PutObjectResult (com.obs.services.model.PutObjectResult)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 NonNull (org.springframework.lang.NonNull)2 UploadResult (run.halo.app.model.support.UploadResult)2 ObsObject (com.obs.services.model.ObsObject)1 ServiceException (com.zhouzifei.tool.common.ServiceException)1