Search in sources :

Example 1 with CopyPartResult

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;
}
Also used : CopyPartRequest(com.qcloud.cos.model.CopyPartRequest) CopyPartResult(com.qcloud.cos.model.CopyPartResult) ResponseNotCompleteException(com.qcloud.cos.exception.ResponseNotCompleteException) CosServiceException(com.qcloud.cos.exception.CosServiceException) CosClientException(com.qcloud.cos.exception.CosClientException) IOException(java.io.IOException)

Example 2 with CopyPartResult

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();
}
Also used : COSClient(com.qcloud.cos.COSClient) CopyPartRequest(com.qcloud.cos.model.CopyPartRequest) COSCredentials(com.qcloud.cos.auth.COSCredentials) BasicCOSCredentials(com.qcloud.cos.auth.BasicCOSCredentials) CosServiceException(com.qcloud.cos.exception.CosServiceException) BasicCOSCredentials(com.qcloud.cos.auth.BasicCOSCredentials) CosClientException(com.qcloud.cos.exception.CosClientException) Region(com.qcloud.cos.region.Region) ClientConfig(com.qcloud.cos.ClientConfig) CopyPartResult(com.qcloud.cos.model.CopyPartResult) PartETag(com.qcloud.cos.model.PartETag)

Example 3 with CopyPartResult

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;
}
Also used : CopyPartResult(com.qcloud.cos.model.CopyPartResult)

Aggregations

CopyPartResult (com.qcloud.cos.model.CopyPartResult)3 CosClientException (com.qcloud.cos.exception.CosClientException)2 CosServiceException (com.qcloud.cos.exception.CosServiceException)2 CopyPartRequest (com.qcloud.cos.model.CopyPartRequest)2 COSClient (com.qcloud.cos.COSClient)1 ClientConfig (com.qcloud.cos.ClientConfig)1 BasicCOSCredentials (com.qcloud.cos.auth.BasicCOSCredentials)1 COSCredentials (com.qcloud.cos.auth.COSCredentials)1 ResponseNotCompleteException (com.qcloud.cos.exception.ResponseNotCompleteException)1 PartETag (com.qcloud.cos.model.PartETag)1 Region (com.qcloud.cos.region.Region)1 IOException (java.io.IOException)1