use of com.qcloud.cos.model.CopyPartResult in project hadoop-cos by tencentyun.
the class CosNativeFileSystemStore method uploadPartCopy.
@Override
public PartETag uploadPartCopy(String uploadId, String srcKey, String destKey, int partNum, long firstByte, long lastByte) throws IOException {
LOG.debug("Execute a part copy from the source key [{}] to the dest key [{}]. " + "upload id: {}, part number: {}, firstByte: {}, lastByte: {}.", srcKey, destKey, uploadId, partNum, firstByte, lastByte);
try {
CopyPartRequest copyPartRequest = new CopyPartRequest();
copyPartRequest.setSourceBucketName(this.bucketName);
copyPartRequest.setDestinationBucketName(this.bucketName);
copyPartRequest.setSourceEndpointBuilder(this.cosClient.getClientConfig().getEndpointBuilder());
copyPartRequest.setUploadId(uploadId);
copyPartRequest.setSourceKey(srcKey);
copyPartRequest.setDestinationKey(destKey);
copyPartRequest.setPartNumber(partNum);
copyPartRequest.setFirstByte(firstByte);
copyPartRequest.setLastByte(lastByte);
CopyPartResult copyPartResult = (CopyPartResult) this.callCOSClientWithRetry(copyPartRequest);
return copyPartResult.getPartETag();
} catch (Exception e) {
String exceptionMessage = String.format("Copy the object part [%d-%d] from the srcKey[%s] to the destKey[%s] failed. " + "upload id: %s, part number: %d, exception: %s.", firstByte, lastByte, srcKey, destKey, uploadId, partNum, e);
handleException(new Exception(exceptionMessage), srcKey);
}
return null;
}
use of com.qcloud.cos.model.CopyPartResult in project cos-java-sdk-v5 by tencentyun.
the class MultipartUploadDemo method copyPartUploadDemo.
// 分块copy, 表示该块的数据来自另外一个文件的某一范围, 支持跨园区, 跨bucket copy
public static void copyPartUploadDemo(String uploadId) {
// 1 初始化用户身份信息(secretId, secretKey)
COSCredentials cred = new BasicCOSCredentials("AKIDXXXXXXXX", "1A2Z3YYYYYYYYYY");
// 2 设置bucket的区域, COS地域的简称请参照 https://www.qcloud.com/document/product/436/6224
ClientConfig clientConfig = new ClientConfig(new Region("ap-guangzhou"));
// 3 生成cos客户端
COSClient cosclient = new COSClient(cred, clientConfig);
// bucket名需包含appid
String bucketName = "mybucket-1251668577";
String key = "aaa/bbb.txt";
CopyPartRequest copyPartRequest = new CopyPartRequest();
// 要拷贝的源文件所在的region
copyPartRequest.setSourceBucketRegion(new Region("ap-guangzhou"));
// 要拷贝的源文件的bucket名称
copyPartRequest.setSourceBucketName(bucketName);
// 要拷贝的源文件的路径
copyPartRequest.setSourceKey("aaa/ccc.txt");
// 指定要拷贝的源文件的数据范围(类似content-range)
copyPartRequest.setFirstByte(0L);
copyPartRequest.setLastByte(1048575L);
// 目的bucket名称
copyPartRequest.setDestinationBucketName(bucketName);
// 目的路径名称
copyPartRequest.setDestinationKey(key);
copyPartRequest.setPartNumber(1);
// uploadId
copyPartRequest.setUploadId(uploadId);
try {
CopyPartResult copyPartResult = cosclient.copyPart(copyPartRequest);
PartETag partETag = copyPartResult.getPartETag();
} catch (CosServiceException e) {
e.printStackTrace();
} catch (CosClientException e) {
e.printStackTrace();
}
cosclient.shutdown();
}
use of com.qcloud.cos.model.CopyPartResult in project cos-java-sdk-v5 by tencentyun.
the class COSCryptoModuleBase method copyPartSecurely.
@Override
public final CopyPartResult copyPartSecurely(CopyPartRequest copyPartRequest) {
String uploadId = copyPartRequest.getUploadId();
MultipartUploadCryptoContext uploadContext = multipartUploadContexts.get(uploadId);
CopyPartResult result = cos.copyPart(copyPartRequest);
if (uploadContext != null && !uploadContext.hasFinalPartBeenSeen())
uploadContext.setHasFinalPartBeenSeen(true);
return result;
}
Aggregations