Search in sources :

Example 1 with HuaWeiObsPostParamRes

use of com.lmxdawn.other.res.HuaWeiObsPostParamRes 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 2 with HuaWeiObsPostParamRes

use of com.lmxdawn.other.res.HuaWeiObsPostParamRes 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)

Aggregations

HuaWeiObsPostParamRes (com.lmxdawn.other.res.HuaWeiObsPostParamRes)2 StorageSettingVo (com.lmxdawn.other.vo.StorageSettingVo)2 ObsClient (com.obs.services.ObsClient)2 ObsConfiguration (com.obs.services.ObsConfiguration)2 HashMap (java.util.HashMap)2 ArrayList (java.util.ArrayList)1