Search in sources :

Example 56 with ObjectMetadata

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

the class PutGetDelTest method testPutObjectWithChineseContentDisposition.

@Test
public void testPutObjectWithChineseContentDisposition() throws IOException {
    ObjectMetadata originObjectMeta = new ObjectMetadata();
    String disposition = "attachment;filename=\"" + UrlEncoderUtils.encode(new String("测试文件.txt".getBytes(), "UTF-8")) + ".jpg\"";
    originObjectMeta.setContentDisposition(disposition);
    testPutObjectByStreamDiffSize(0L, originObjectMeta);
}
Also used : ObjectMetadata(com.qcloud.cos.model.ObjectMetadata) Test(org.junit.Test)

Example 57 with ObjectMetadata

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

the class PutObjectCopyTest method testCopySameRegion10MWithNewMetaData.

@Test
public void testCopySameRegion10MWithNewMetaData() throws IOException {
    ObjectMetadata newObjectMetadata = new ObjectMetadata();
    newObjectMetadata.setServerSideEncryption("AES256");
    newObjectMetadata.setContentType("image/png");
    newObjectMetadata.setCacheControl("no-cache");
    testCopySameRegionDiffSize(10 * 1024 * 1024L, newObjectMetadata);
}
Also used : ObjectMetadata(com.qcloud.cos.model.ObjectMetadata) Test(org.junit.Test)

Example 58 with ObjectMetadata

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

the class RestoreObjectTest method restoreObject.

@Test
public void restoreObject() {
    InputStream input = new ByteArrayInputStream(new byte[10]);
    ObjectMetadata objectMetadata = new ObjectMetadata();
    objectMetadata.setContentLength(10);
    String key = "ut/aaa.txt";
    PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, key, input, objectMetadata);
    putObjectRequest.setStorageClass(StorageClass.Archive);
    cosclient.putObject(putObjectRequest);
    RestoreObjectRequest restoreObjectRequest = new RestoreObjectRequest(bucket, key, 1);
    cosclient.restoreObject(restoreObjectRequest);
    cosclient.deleteObject(bucket, key);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) RestoreObjectRequest(com.qcloud.cos.model.RestoreObjectRequest) ObjectMetadata(com.qcloud.cos.model.ObjectMetadata) PutObjectRequest(com.qcloud.cos.model.PutObjectRequest) Test(org.junit.Test)

Example 59 with ObjectMetadata

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

the class PutGetDelTest method testPutObjectWithGzipEncoding.

@Test
public void testPutObjectWithGzipEncoding() throws IOException {
    ObjectMetadata originObjectMeta = new ObjectMetadata();
    originObjectMeta.setContentEncoding("gzip");
    testPutObjectByStreamDiffSize(1024 * 1024L, originObjectMeta);
}
Also used : ObjectMetadata(com.qcloud.cos.model.ObjectMetadata) Test(org.junit.Test)

Example 60 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)

Aggregations

ObjectMetadata (com.qcloud.cos.model.ObjectMetadata)77 CosClientException (com.qcloud.cos.exception.CosClientException)26 CosServiceException (com.qcloud.cos.exception.CosServiceException)23 IOException (java.io.IOException)22 File (java.io.File)21 PutObjectRequest (com.qcloud.cos.model.PutObjectRequest)17 COSClient (com.qcloud.cos.COSClient)15 ClientConfig (com.qcloud.cos.ClientConfig)14 GetObjectRequest (com.qcloud.cos.model.GetObjectRequest)14 PutObjectResult (com.qcloud.cos.model.PutObjectResult)14 Region (com.qcloud.cos.region.Region)14 ResponseNotCompleteException (com.qcloud.cos.exception.ResponseNotCompleteException)13 BasicCOSCredentials (com.qcloud.cos.auth.BasicCOSCredentials)12 COSCredentials (com.qcloud.cos.auth.COSCredentials)12 Test (org.junit.Test)11 GetObjectMetadataRequest (com.qcloud.cos.model.GetObjectMetadataRequest)9 ByteArrayInputStream (java.io.ByteArrayInputStream)9 InputStream (java.io.InputStream)8 CopyObjectRequest (com.qcloud.cos.model.CopyObjectRequest)7 COSObject (com.qcloud.cos.model.COSObject)6