Search in sources :

Example 11 with PutObjectResult

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

the class AbstractCOSClientTest method putObjectFromLocalFileByInputStream.

protected static void putObjectFromLocalFileByInputStream(File localFile, long uploadSize, String uploadEtag, String key, ObjectMetadata objectMetadata) {
    if (!judgeUserInfoValid()) {
        return;
    }
    FileInputStream input = null;
    try {
        input = new FileInputStream(localFile);
        PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, key, input, objectMetadata);
        putObjectRequest.setStorageClass(StorageClass.Standard_IA);
        PutObjectResult putObjectResult = cosclient.putObject(putObjectRequest);
        String etag = putObjectResult.getETag();
        if (useClientEncryption) {
            assertEquals(false, uploadEtag.equals(etag));
        } else {
            assertEquals(true, uploadEtag.equals(etag));
        }
    } catch (IOException e) {
        fail(e.toString());
    } finally {
        if (input != null) {
            try {
                input.close();
            } catch (IOException e) {
            }
        }
    }
}
Also used : PutObjectResult(com.qcloud.cos.model.PutObjectResult) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) PutObjectRequest(com.qcloud.cos.model.PutObjectRequest)

Example 12 with PutObjectResult

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

the class ListVersionsTest method putTestFile.

public void putTestFile(boolean retVersionFlag) throws Exception {
    for (int i = 0; i < fileNum; ++i) {
        for (int j = 0; j < eachFileVersionNum; ++j) {
            long localFileSize = (i + 1) * 1024L;
            String key = String.format("%s/%06dk", keyPrefix, i);
            File localFile = buildTestFile(localFileSize);
            localFileArray[i * eachFileVersionNum + j] = localFile;
            keyArray[i * eachFileVersionNum + j] = key;
            PutObjectResult putObjectResult = putObjectFromLocalFile(localFile, key);
            if (retVersionFlag) {
                assertNotNull("put object for version enalbed bucket should return versonId", putObjectResult.getVersionId());
            } else {
                assertEquals(null, putObjectResult.getVersionId());
            }
        }
    }
}
Also used : PutObjectResult(com.qcloud.cos.model.PutObjectResult) File(java.io.File)

Example 13 with PutObjectResult

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

the class UploadCallable method uploadInOneChunk.

/**
 * Uploads the given request in a single chunk and returns the result.
 */
private UploadResult uploadInOneChunk() {
    PutObjectResult putObjectResult = cos.putObject(origReq);
    UploadResult uploadResult = new UploadResult();
    uploadResult.setBucketName(origReq.getBucketName());
    uploadResult.setKey(origReq.getKey());
    uploadResult.setETag(putObjectResult.getETag());
    uploadResult.setVersionId(putObjectResult.getVersionId());
    uploadResult.setRequestId(putObjectResult.getRequestId());
    uploadResult.setDateStr(putObjectResult.getDateStr());
    uploadResult.setCrc64Ecma(putObjectResult.getCrc64Ecma());
    uploadResult.setCiUploadResult(putObjectResult.getCiUploadResult());
    return uploadResult;
}
Also used : PutObjectResult(com.qcloud.cos.model.PutObjectResult) CompleteMultipartUploadResult(com.qcloud.cos.model.CompleteMultipartUploadResult) UploadResult(com.qcloud.cos.model.UploadResult)

Example 14 with PutObjectResult

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

the class PutGetDelTest method putObjectFromString.

private void putObjectFromString(String key, String content) throws IOException {
    if (!judgeUserInfoValid()) {
        return;
    }
    File downloadFile = buildTestFile(0L);
    try {
        String contentEtag = Md5Utils.md5Hex(content);
        PutObjectResult putObjectResult = cosclient.putObject(bucket, key, content);
        String etag = putObjectResult.getETag();
        assertEquals(!useClientEncryption, contentEtag.equals(etag));
        headSimpleObject(key, content.getBytes(StringUtils.UTF8).length, contentEtag);
        getObject(key, downloadFile, null, content.getBytes(StringUtils.UTF8).length, contentEtag);
        cosclient.getObjectMetadata(bucket, key);
    } finally {
        cosclient.deleteObject(bucket, key);
        assertTrue(downloadFile.delete());
    }
}
Also used : PutObjectResult(com.qcloud.cos.model.PutObjectResult) File(java.io.File)

Example 15 with PutObjectResult

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

the class BatchDeleteTest method batchDeleteAllExistFileForVersionEnabled.

@Test
public void batchDeleteAllExistFileForVersionEnabled() throws IOException, InterruptedException {
    if (!judgeUserInfoValid()) {
        return;
    }
    BucketVersioningConfiguration bucketVersioningEnabled = new BucketVersioningConfiguration(BucketVersioningConfiguration.ENABLED);
    cosclient.setBucketVersioningConfiguration(new SetBucketVersioningConfigurationRequest(bucket, bucketVersioningEnabled));
    Thread.sleep(5000L);
    DeleteObjectsRequest deleteObjectsRequest = new DeleteObjectsRequest(bucket);
    ArrayList<KeyVersion> keyList = new ArrayList<>();
    long deleteFileCount = 30;
    for (long fileIndex = 0; fileIndex < deleteFileCount; ++fileIndex) {
        File localFile = buildTestFile(fileIndex * 1024);
        String key = "ut/" + localFile.getName();
        PutObjectResult putObjectResult = putObjectFromLocalFile(localFile, key);
        keyList.add(new KeyVersion(key, putObjectResult.getVersionId()));
    }
    deleteObjectsRequest.setKeys(keyList);
    DeleteObjectsResult deleteObjectsResult = cosclient.deleteObjects(deleteObjectsRequest);
    assertEquals(deleteFileCount, deleteObjectsResult.getDeletedObjects().size());
}
Also used : PutObjectResult(com.qcloud.cos.model.PutObjectResult) KeyVersion(com.qcloud.cos.model.DeleteObjectsRequest.KeyVersion) SetBucketVersioningConfigurationRequest(com.qcloud.cos.model.SetBucketVersioningConfigurationRequest) ArrayList(java.util.ArrayList) BucketVersioningConfiguration(com.qcloud.cos.model.BucketVersioningConfiguration) DeleteObjectsResult(com.qcloud.cos.model.DeleteObjectsResult) File(java.io.File) DeleteObjectsRequest(com.qcloud.cos.model.DeleteObjectsRequest) Test(org.junit.Test)

Aggregations

PutObjectResult (com.qcloud.cos.model.PutObjectResult)37 PutObjectRequest (com.qcloud.cos.model.PutObjectRequest)25 File (java.io.File)20 COSClient (com.qcloud.cos.COSClient)14 ClientConfig (com.qcloud.cos.ClientConfig)14 CosServiceException (com.qcloud.cos.exception.CosServiceException)14 ObjectMetadata (com.qcloud.cos.model.ObjectMetadata)14 Region (com.qcloud.cos.region.Region)14 CosClientException (com.qcloud.cos.exception.CosClientException)12 BasicCOSCredentials (com.qcloud.cos.auth.BasicCOSCredentials)11 COSCredentials (com.qcloud.cos.auth.COSCredentials)11 IOException (java.io.IOException)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 CIObject (com.qcloud.cos.model.ciModel.persistence.CIObject)4 CIUploadResult (com.qcloud.cos.model.ciModel.persistence.CIUploadResult)4 PicOperations (com.qcloud.cos.model.ciModel.persistence.PicOperations)4 InputStream (java.io.InputStream)4 LinkedList (java.util.LinkedList)4 Test (org.junit.Test)4 FileOperationException (run.halo.app.exception.FileOperationException)3