Search in sources :

Example 1 with EndpointBuilder

use of com.qcloud.cos.endpoint.EndpointBuilder in project cos-java-sdk-v5 by tencentyun.

the class COSClient method populateRequestWithCopyPartParameters.

private void populateRequestWithCopyPartParameters(CosHttpRequest<? extends CosServiceRequest> request, CopyPartRequest copyPartRequest) {
    Region sourceRegion = copyPartRequest.getSourceBucketRegion();
    EndpointBuilder srcEndpointBuilder = null;
    // 如果用户没有设置源region, 则默认和目的region一致
    if (sourceRegion == null) {
        srcEndpointBuilder = this.clientConfig.getEndpointBuilder();
    } else {
        srcEndpointBuilder = new RegionEndpointBuilder(sourceRegion);
    }
    if (copyPartRequest.getSourceEndpointBuilder() != null) {
        srcEndpointBuilder = copyPartRequest.getSourceEndpointBuilder();
    }
    String sourceKey = formatKey(copyPartRequest.getSourceKey());
    String sourceBucket = formatBucket(copyPartRequest.getSourceBucketName(), (copyPartRequest.getSourceAppid() != null) ? copyPartRequest.getSourceAppid() : fetchCredential().getCOSAppId());
    String copySourceHeader = String.format("%s%s", srcEndpointBuilder.buildGeneralApiEndpoint(sourceBucket), UrlEncoderUtils.encodeEscapeDelimiter(sourceKey));
    if (copyPartRequest.getSourceVersionId() != null) {
        copySourceHeader += "?versionId=" + copyPartRequest.getSourceVersionId();
    }
    request.addHeader("x-cos-copy-source", copySourceHeader);
    addDateHeader(request, Headers.COPY_SOURCE_IF_MODIFIED_SINCE, copyPartRequest.getModifiedSinceConstraint());
    addDateHeader(request, Headers.COPY_SOURCE_IF_UNMODIFIED_SINCE, copyPartRequest.getUnmodifiedSinceConstraint());
    addStringListHeader(request, Headers.COPY_SOURCE_IF_MATCH, copyPartRequest.getMatchingETagConstraints());
    addStringListHeader(request, Headers.COPY_SOURCE_IF_NO_MATCH, copyPartRequest.getNonmatchingETagConstraints());
    if (copyPartRequest.getFirstByte() != null && copyPartRequest.getLastByte() != null) {
        String range = "bytes=" + copyPartRequest.getFirstByte() + "-" + copyPartRequest.getLastByte();
        request.addHeader(Headers.COPY_PART_RANGE, range);
    }
    // Populate the SSE-C parameters for the source and destination object
    populateSSE_C(request, copyPartRequest.getDestinationSSECustomerKey());
    populateSourceSSE_C(request, copyPartRequest.getSourceSSECustomerKey());
}
Also used : Region(com.qcloud.cos.region.Region) RegionEndpointBuilder(com.qcloud.cos.endpoint.RegionEndpointBuilder) EndpointBuilder(com.qcloud.cos.endpoint.EndpointBuilder) CIRegionEndpointBuilder(com.qcloud.cos.endpoint.CIRegionEndpointBuilder) RegionEndpointBuilder(com.qcloud.cos.endpoint.RegionEndpointBuilder) CIRegionEndpointBuilder(com.qcloud.cos.endpoint.CIRegionEndpointBuilder)

Example 2 with EndpointBuilder

use of com.qcloud.cos.endpoint.EndpointBuilder in project cos-java-sdk-v5 by tencentyun.

the class COSClient method populateRequestWithCopyObjectParameters.

private void populateRequestWithCopyObjectParameters(CosHttpRequest<? extends CosServiceRequest> request, CopyObjectRequest copyObjectRequest) {
    Region sourceRegion = copyObjectRequest.getSourceBucketRegion();
    EndpointBuilder srcEndpointBuilder = null;
    // 如果用户没有设置源region, 则默认和目的region一致
    if (sourceRegion == null) {
        srcEndpointBuilder = this.clientConfig.getEndpointBuilder();
    } else {
        srcEndpointBuilder = new RegionEndpointBuilder(sourceRegion);
    }
    if (copyObjectRequest.getSourceEndpointBuilder() != null) {
        srcEndpointBuilder = copyObjectRequest.getSourceEndpointBuilder();
    }
    String sourceKey = formatKey(copyObjectRequest.getSourceKey());
    String sourceBucket = formatBucket(copyObjectRequest.getSourceBucketName(), (copyObjectRequest.getSourceAppid() != null) ? copyObjectRequest.getSourceAppid() : fetchCredential().getCOSAppId());
    String copySourceHeader = String.format("%s%s", srcEndpointBuilder.buildGeneralApiEndpoint(sourceBucket), UrlEncoderUtils.encodeEscapeDelimiter(sourceKey));
    if (copyObjectRequest.getSourceVersionId() != null) {
        copySourceHeader += "?versionId=" + copyObjectRequest.getSourceVersionId();
    }
    request.addHeader("x-cos-copy-source", copySourceHeader);
    addDateHeader(request, Headers.COPY_SOURCE_IF_MODIFIED_SINCE, copyObjectRequest.getModifiedSinceConstraint());
    addDateHeader(request, Headers.COPY_SOURCE_IF_UNMODIFIED_SINCE, copyObjectRequest.getUnmodifiedSinceConstraint());
    addStringListHeader(request, Headers.COPY_SOURCE_IF_MATCH, copyObjectRequest.getMatchingETagConstraints());
    addStringListHeader(request, Headers.COPY_SOURCE_IF_NO_MATCH, copyObjectRequest.getNonmatchingETagConstraints());
    if (copyObjectRequest.getAccessControlList() != null) {
        addAclHeaders(request, copyObjectRequest.getAccessControlList());
    } else if (copyObjectRequest.getCannedAccessControlList() != null) {
        request.addHeader(Headers.COS_CANNED_ACL, copyObjectRequest.getCannedAccessControlList().toString());
    }
    if (copyObjectRequest.getStorageClass() != null) {
        request.addHeader(Headers.STORAGE_CLASS, copyObjectRequest.getStorageClass());
    }
    if (copyObjectRequest.getRedirectLocation() != null) {
        request.addHeader(Headers.REDIRECT_LOCATION, copyObjectRequest.getRedirectLocation());
    }
    ObjectMetadata newObjectMetadata = copyObjectRequest.getNewObjectMetadata();
    if (copyObjectRequest.getMetadataDirective() != null) {
        request.addHeader(Headers.METADATA_DIRECTIVE, copyObjectRequest.getMetadataDirective());
    } else if (newObjectMetadata != null) {
        request.addHeader(Headers.METADATA_DIRECTIVE, "REPLACE");
    }
    if (newObjectMetadata != null) {
        populateRequestMetadata(request, newObjectMetadata);
    }
    // Populate the SSE-C parameters for the source and destination object
    populateSSE_C(request, copyObjectRequest.getDestinationSSECustomerKey());
    populateSourceSSE_C(request, copyObjectRequest.getSourceSSECustomerKey());
    populateSSE_KMS(request, copyObjectRequest.getSSECOSKeyManagementParams());
}
Also used : Region(com.qcloud.cos.region.Region) RegionEndpointBuilder(com.qcloud.cos.endpoint.RegionEndpointBuilder) EndpointBuilder(com.qcloud.cos.endpoint.EndpointBuilder) CIRegionEndpointBuilder(com.qcloud.cos.endpoint.CIRegionEndpointBuilder) RegionEndpointBuilder(com.qcloud.cos.endpoint.RegionEndpointBuilder) CIRegionEndpointBuilder(com.qcloud.cos.endpoint.CIRegionEndpointBuilder)

Example 3 with EndpointBuilder

use of com.qcloud.cos.endpoint.EndpointBuilder in project cos-java-sdk-v5 by tencentyun.

the class GetAsyncFetchTaskDemo method getAsyncFetchTask.

public static void getAsyncFetchTask() {
    EndpointBuilder builder = new UserSpecifiedEndpointBuilder(String.format("%s.migration.myqcloud.com", region), "service.cos.myqcloud.com");
    COSClient cosClient = createCosClient();
    cosClient.getClientConfig().setEndpointBuilder(builder);
    GetAsyncFetchTaskRequest request = new GetAsyncFetchTaskRequest();
    request.setBucketName(bucketName);
    request.setTaskId(taskId);
    GetAsyncFetchTaskResult result = cosClient.getAsyncFetchTask(request);
    System.out.println(result.getCosRequestId());
    System.out.println(result.getCode());
    System.out.println(result.getMessage());
    System.out.println(result.getRequestId());
    for (Entry<String, String> entry : result.getData().entrySet()) {
        System.out.println(entry.getKey());
        System.out.println(entry.getValue());
    }
}
Also used : COSClient(com.qcloud.cos.COSClient) GetAsyncFetchTaskResult(com.qcloud.cos.model.fetch.GetAsyncFetchTaskResult) GetAsyncFetchTaskRequest(com.qcloud.cos.model.fetch.GetAsyncFetchTaskRequest) UserSpecifiedEndpointBuilder(com.qcloud.cos.endpoint.UserSpecifiedEndpointBuilder) UserSpecifiedEndpointBuilder(com.qcloud.cos.endpoint.UserSpecifiedEndpointBuilder) EndpointBuilder(com.qcloud.cos.endpoint.EndpointBuilder)

Example 4 with EndpointBuilder

use of com.qcloud.cos.endpoint.EndpointBuilder in project cos-java-sdk-v5 by tencentyun.

the class PutAsyncFetchTaskDemo method putAsyncFetchTask.

public static void putAsyncFetchTask() {
    EndpointBuilder builder = new UserSpecifiedEndpointBuilder(String.format("%s.migration.myqcloud.com", region), "service.cos.myqcloud.com");
    COSClient cosClient = createCosClient();
    cosClient.getClientConfig().setEndpointBuilder(builder);
    PutAsyncFetchTaskRequest request = new PutAsyncFetchTaskRequest();
    request.setBucketName(bucketName);
    request.setUrl("https://pic1.zhimg.com/v2-63fc555d77019ae08ac2281a2418dcc7_720w.jpg");
    request.setIgnoreSameKey(false);
    request.setKey("test_fetch");
    request.setOnKeyExist("override");
    // 可选
    // reqeust.setSuccessCallbackUrl("");
    // request.setFailureCallbackUrl("");
    // request.setMd5("");
    PutAsyncFetchTaskResult result = cosClient.putAsyncFetchTask(request);
    System.out.println(result.getCosRequestId());
    System.out.println(result.getCode());
    System.out.println(result.getMessage());
    System.out.println(result.getRequestId());
    for (Entry<String, String> entry : result.getData().entrySet()) {
        System.out.println(entry.getKey());
        System.out.println(entry.getValue());
    }
}
Also used : COSClient(com.qcloud.cos.COSClient) PutAsyncFetchTaskRequest(com.qcloud.cos.model.fetch.PutAsyncFetchTaskRequest) PutAsyncFetchTaskResult(com.qcloud.cos.model.fetch.PutAsyncFetchTaskResult) UserSpecifiedEndpointBuilder(com.qcloud.cos.endpoint.UserSpecifiedEndpointBuilder) UserSpecifiedEndpointBuilder(com.qcloud.cos.endpoint.UserSpecifiedEndpointBuilder) EndpointBuilder(com.qcloud.cos.endpoint.EndpointBuilder)

Aggregations

EndpointBuilder (com.qcloud.cos.endpoint.EndpointBuilder)4 COSClient (com.qcloud.cos.COSClient)2 CIRegionEndpointBuilder (com.qcloud.cos.endpoint.CIRegionEndpointBuilder)2 RegionEndpointBuilder (com.qcloud.cos.endpoint.RegionEndpointBuilder)2 UserSpecifiedEndpointBuilder (com.qcloud.cos.endpoint.UserSpecifiedEndpointBuilder)2 Region (com.qcloud.cos.region.Region)2 GetAsyncFetchTaskRequest (com.qcloud.cos.model.fetch.GetAsyncFetchTaskRequest)1 GetAsyncFetchTaskResult (com.qcloud.cos.model.fetch.GetAsyncFetchTaskResult)1 PutAsyncFetchTaskRequest (com.qcloud.cos.model.fetch.PutAsyncFetchTaskRequest)1 PutAsyncFetchTaskResult (com.qcloud.cos.model.fetch.PutAsyncFetchTaskResult)1