Search in sources :

Example 46 with ObjectMetadata

use of com.qcloud.cos.model.ObjectMetadata in project cos-java-sdk-v5 by tencentyun.

the class CompleteMultipartUpload method call.

@Override
public UploadResult call() throws Exception {
    CompleteMultipartUploadResult res;
    try {
        CompleteMultipartUploadRequest req = new CompleteMultipartUploadRequest(origReq.getBucketName(), origReq.getKey(), uploadId, collectPartETags()).withGeneralProgressListener(origReq.getGeneralProgressListener());
        ObjectMetadata origMeta = origReq.getMetadata();
        if (origMeta != null) {
            ObjectMetadata objMeta = req.getObjectMetadata();
            if (objMeta == null) {
                objMeta = new ObjectMetadata();
            }
            objMeta.setUserMetadata(origMeta.getUserMetadata());
            req.setObjectMetadata(objMeta);
        }
        if (origReq.getPicOperations() != null) {
            req.setPicOperations(origReq.getPicOperations());
        }
        TransferManagerUtils.populateEndpointAddr(origReq, req);
        res = cos.completeMultipartUpload(req);
    } catch (Exception e) {
        monitor.uploadFailed();
        throw e;
    }
    UploadResult uploadResult = new UploadResult();
    uploadResult.setBucketName(origReq.getBucketName());
    uploadResult.setKey(origReq.getKey());
    uploadResult.setETag(res.getETag());
    uploadResult.setVersionId(res.getVersionId());
    uploadResult.setRequestId(res.getRequestId());
    uploadResult.setDateStr(res.getDateStr());
    uploadResult.setCrc64Ecma(res.getCrc64Ecma());
    uploadResult.setCiUploadResult(res.getCiUploadResult());
    monitor.uploadComplete();
    return uploadResult;
}
Also used : CompleteMultipartUploadResult(com.qcloud.cos.model.CompleteMultipartUploadResult) CompleteMultipartUploadResult(com.qcloud.cos.model.CompleteMultipartUploadResult) UploadResult(com.qcloud.cos.model.UploadResult) ObjectMetadata(com.qcloud.cos.model.ObjectMetadata) CosClientException(com.qcloud.cos.exception.CosClientException) CompleteMultipartUploadRequest(com.qcloud.cos.model.CompleteMultipartUploadRequest)

Example 47 with ObjectMetadata

use of com.qcloud.cos.model.ObjectMetadata in project cos-java-sdk-v5 by tencentyun.

the class KMSEncryptionClientDemo method getObjectDemo.

static void getObjectDemo() {
    // 下载文件
    GetObjectRequest getObjectRequest = new GetObjectRequest(bucketName, key);
    File downloadFile = new File("downlen1m.txt");
    ObjectMetadata objectMetadata = cosClient.getObject(getObjectRequest, downloadFile);
    System.out.println(objectMetadata.getRequestId());
}
Also used : GetObjectRequest(com.qcloud.cos.model.GetObjectRequest) File(java.io.File) ObjectMetadata(com.qcloud.cos.model.ObjectMetadata)

Example 48 with ObjectMetadata

use of com.qcloud.cos.model.ObjectMetadata in project cos-java-sdk-v5 by tencentyun.

the class AsymmetricKeyEncryptionClientDemo method getObjectDemo.

static void getObjectDemo() {
    // 下载文件
    GetObjectRequest getObjectRequest = new GetObjectRequest(bucketName, key);
    File downloadFile = new File("downAsy.txt");
    ObjectMetadata objectMetadata = cosClient.getObject(getObjectRequest, downloadFile);
    System.out.println(objectMetadata.getRequestId());
}
Also used : GetObjectRequest(com.qcloud.cos.model.GetObjectRequest) File(java.io.File) ObjectMetadata(com.qcloud.cos.model.ObjectMetadata)

Example 49 with ObjectMetadata

use of com.qcloud.cos.model.ObjectMetadata in project cos-java-sdk-v5 by tencentyun.

the class CAMRoleDemo method SimpleUploadFileFromEMR.

public static void SimpleUploadFileFromEMR() {
    InstanceMetadataCredentialsEndpointProvider endpointProvider = new InstanceMetadataCredentialsEndpointProvider(InstanceMetadataCredentialsEndpointProvider.Instance.EMR);
    InstanceCredentialsFetcher instanceCredentialsFetcher = new InstanceCredentialsFetcher(endpointProvider);
    COSCredentialsProvider cosCredentialsProvider = new InstanceCredentialsProvider(instanceCredentialsFetcher);
    COSCredentials cred = cosCredentialsProvider.getCredentials();
    System.out.println(cred.getCOSAccessKeyId());
    System.out.println(cred.getCOSSecretKey());
    System.out.println(cred.getCOSAppId());
    ClientConfig clientConfig = new ClientConfig(new Region("ap-chongqing"));
    COSClient cosClient = new COSClient(cosCredentialsProvider, clientConfig);
    String bucketName = "aaa-125xxx";
    String key = "test_emr.txt";
    File localFile = new File("./test");
    PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key, localFile);
    putObjectRequest.setStorageClass(StorageClass.Standard);
    PutObjectResult putObjectResult = cosClient.putObject(putObjectRequest);
    System.out.println("upload file etag: " + putObjectResult.getETag());
    System.out.println("upload file requestId: " + putObjectResult.getRequestId());
    ObjectMetadata getMeta = cosClient.getObjectMetadata(bucketName, key);
    System.out.println("get file etag: " + getMeta.getETag());
    cosClient.deleteObject(bucketName, key);
    if (cosClient.doesObjectExist(bucketName, key)) {
        System.out.println("delete failed");
    } else {
        System.out.println("delete successfully");
    }
    cosClient.shutdown();
}
Also used : PutObjectResult(com.qcloud.cos.model.PutObjectResult) COSClient(com.qcloud.cos.COSClient) Region(com.qcloud.cos.region.Region) ClientConfig(com.qcloud.cos.ClientConfig) File(java.io.File) ObjectMetadata(com.qcloud.cos.model.ObjectMetadata) PutObjectRequest(com.qcloud.cos.model.PutObjectRequest)

Example 50 with ObjectMetadata

use of com.qcloud.cos.model.ObjectMetadata in project cos-java-sdk-v5 by tencentyun.

the class GetObjectMetadataDemo method getObjectMetadataDemo.

// 将本地文件上传到COS
public static void getObjectMetadataDemo() {
    // 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-beijing-1"));
    // 3 生成cos客户端
    COSClient cosclient = new COSClient(cred, clientConfig);
    // bucket名需包含appid
    String bucketName = "mybucket-1251668577";
    String key = "aaa/bbb.txt";
    ObjectMetadata objectMetadata = cosclient.getObjectMetadata(bucketName, key);
    System.out.println(objectMetadata.getCrc64Ecma());
    System.out.println(objectMetadata.getLastModified());
    // 关闭客户端
    cosclient.shutdown();
}
Also used : COSClient(com.qcloud.cos.COSClient) COSCredentials(com.qcloud.cos.auth.COSCredentials) BasicCOSCredentials(com.qcloud.cos.auth.BasicCOSCredentials) BasicCOSCredentials(com.qcloud.cos.auth.BasicCOSCredentials) Region(com.qcloud.cos.region.Region) ClientConfig(com.qcloud.cos.ClientConfig) ObjectMetadata(com.qcloud.cos.model.ObjectMetadata)

Aggregations

ObjectMetadata (com.qcloud.cos.model.ObjectMetadata)64 File (java.io.File)21 COSClient (com.qcloud.cos.COSClient)15 PutObjectRequest (com.qcloud.cos.model.PutObjectRequest)15 ClientConfig (com.qcloud.cos.ClientConfig)14 Region (com.qcloud.cos.region.Region)14 CosClientException (com.qcloud.cos.exception.CosClientException)13 BasicCOSCredentials (com.qcloud.cos.auth.BasicCOSCredentials)12 COSCredentials (com.qcloud.cos.auth.COSCredentials)12 PutObjectResult (com.qcloud.cos.model.PutObjectResult)12 GetObjectRequest (com.qcloud.cos.model.GetObjectRequest)11 Test (org.junit.Test)11 CosServiceException (com.qcloud.cos.exception.CosServiceException)10 IOException (java.io.IOException)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8 InputStream (java.io.InputStream)7 GetObjectMetadataRequest (com.qcloud.cos.model.GetObjectMetadataRequest)6 UploadResult (com.qcloud.cos.model.UploadResult)5 TransferManager (com.qcloud.cos.transfer.TransferManager)5 Upload (com.qcloud.cos.transfer.Upload)5