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());
}
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());
}
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());
}
}
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());
}
}
Aggregations