use of com.qcloud.cos.model.ObjectMetadata in project cos-java-sdk-v5 by tencentyun.
the class PutObjectCopyTest method testUpdateObjectAttr.
@Test
public void testUpdateObjectAttr() throws IOException {
ObjectMetadata newMetadata = new ObjectMetadata();
newMetadata.setContentType("application/json");
newMetadata.setContentDisposition("filename=\"abc.txt\"");
newMetadata.setCacheControl("no-cache");
newMetadata.setContentEncoding("gzip");
newMetadata.addUserMetadata("school", "football sport");
testUpdateDiffSize(0, newMetadata);
}
use of com.qcloud.cos.model.ObjectMetadata in project cos-java-sdk-v5 by tencentyun.
the class TransferManagerTest method testTransferManagerUploadDownBigFile.
@Test
public void testTransferManagerUploadDownBigFile() throws IOException, CosServiceException, CosClientException, InterruptedException {
if (!judgeUserInfoValid()) {
return;
}
TransferManager transferManager = new TransferManager(cosclient);
File localFile = buildTestFile(1024 * 1024 * 10L);
File downFile = new File(localFile.getAbsolutePath() + ".down");
String key = "ut/" + localFile.getName();
String destKey = key + ".copy";
try {
PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, key, localFile);
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setServerSideEncryption("AES256");
putObjectRequest.setMetadata(objectMetadata);
Upload upload = transferManager.upload(putObjectRequest);
UploadResult uploadResult = upload.waitForUploadResult();
assertTrue(uploadResult.getETag().contains("-"));
assertTrue(upload.isResumeableMultipartUploadAfterFailed());
assertNotNull(upload.getResumeableMultipartUploadId());
assertNotNull(uploadResult.getRequestId());
assertNotNull(uploadResult.getDateStr());
GetObjectRequest getObjectRequest = new GetObjectRequest(bucket, key);
Download download = transferManager.download(getObjectRequest, downFile);
download.waitForCompletion();
// check file
assertEquals(Md5Utils.md5Hex(localFile), Md5Utils.md5Hex(downFile));
CopyObjectRequest copyObjectRequest = new CopyObjectRequest(bucket, key, bucket, destKey);
Copy copy = transferManager.copy(copyObjectRequest, cosclient, null);
copy.waitForCompletion();
} finally {
// delete file on cos
clearObject(key);
// delete file on cos
clearObject(destKey);
if (localFile.exists()) {
assertTrue(localFile.delete());
}
if (downFile.exists()) {
assertTrue(downFile.delete());
}
}
}
use of com.qcloud.cos.model.ObjectMetadata in project cos-java-sdk-v5 by tencentyun.
the class AbstractCOSClientTest method testAppendGetDelObjectDiffSize.
protected void testAppendGetDelObjectDiffSize(long size, boolean isStream) throws IOException {
String key = "ut/" + size;
long nextAppendPosition = 0;
for (int i = 0; i < 3; i++) {
File localFile = buildTestFile(size);
AppendObjectRequest appendObjectRequest = null;
if (!isStream) {
appendObjectRequest = new AppendObjectRequest(bucket, key, localFile);
} else {
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setContentLength(size);
appendObjectRequest = new AppendObjectRequest(bucket, key, new FileInputStream(localFile), objectMetadata);
}
appendObjectRequest.setPosition(nextAppendPosition);
AppendObjectResult appendObjectResult = cosclient.appendObject(appendObjectRequest);
nextAppendPosition = appendObjectResult.getNextAppendPosition();
localFile.delete();
}
ObjectMetadata objectMetadata = cosclient.getObjectMetadata(bucket, key);
assertEquals(objectMetadata.getContentLength(), size * 3);
cosclient.deleteObject(bucket, key);
}
use of com.qcloud.cos.model.ObjectMetadata in project cos-java-sdk-v5 by tencentyun.
the class AbstractCOSClientTest method getObject.
// 下载COS的object
protected static void getObject(String key, File localDownFile, long[] range, long expectedLength, String expectedMd5) {
System.setProperty(SkipMd5CheckStrategy.DISABLE_GET_OBJECT_MD5_VALIDATION_PROPERTY, "true");
GetObjectRequest getObjectRequest = new GetObjectRequest(bucket, key);
ResponseHeaderOverrides responseHeaders = new ResponseHeaderOverrides();
String responseContentType = "image/x-icon";
String responseContentLanguage = "zh-CN";
String responseContentDispositon = "filename=\"abc.txt\"";
String responseCacheControl = "no-cache";
String expireStr = DateUtils.formatRFC822Date(new Date(System.currentTimeMillis() + 24 * 3600 * 1000));
responseHeaders.setContentType(responseContentType);
responseHeaders.setContentLanguage(responseContentLanguage);
responseHeaders.setContentDisposition(responseContentDispositon);
responseHeaders.setCacheControl(responseCacheControl);
responseHeaders.setExpires(expireStr);
getObjectRequest.setResponseHeaders(responseHeaders);
if (range != null) {
if (range[1] == range[0] && range[1] == 0) {
assertEquals(expectedLength, 1);
getObjectRequest.setRange(range[0], range[1]);
} else {
assertEquals(expectedLength, range[1] - range[0] + 1);
getObjectRequest.setRange(range[0], range[1]);
}
}
try {
ObjectMetadata objectMetadata = cosclient.getObject(getObjectRequest, localDownFile);
assertEquals(responseContentType, objectMetadata.getContentType());
assertEquals(responseContentLanguage, objectMetadata.getContentLanguage());
assertEquals(responseContentDispositon, objectMetadata.getContentDisposition());
assertEquals(responseCacheControl, objectMetadata.getCacheControl());
assertEquals(expectedLength, localDownFile.length());
assertEquals(expectedMd5, Md5Utils.md5Hex(localDownFile));
} catch (SecurityException se) {
if (cosclient instanceof COSEncryptionClient && cryptoConfiguration != null && cryptoConfiguration.getCryptoMode() == CryptoMode.StrictAuthenticatedEncryption && range != null) {
return;
}
fail(se.toString());
} catch (Exception e) {
fail(e.toString());
}
}
use of com.qcloud.cos.model.ObjectMetadata in project cos-java-sdk-v5 by tencentyun.
the class AbstractCOSClientTest method headSimpleObject.
protected static ObjectMetadata headSimpleObject(String key, long expectedLength, String expectedEtag) {
ObjectMetadata objectMetadata = cosclient.getObjectMetadata(new GetObjectMetadataRequest(bucket, key));
if (!useClientEncryption) {
assertEquals(expectedLength, objectMetadata.getContentLength());
} else {
assertEquals(expectedLength, Long.valueOf(objectMetadata.getUserMetaDataOf(Headers.UNENCRYPTED_CONTENT_LENGTH)).longValue());
}
if (useClientEncryption) {
assertEquals(false, expectedEtag.equals(objectMetadata.getETag()));
} else {
assertEquals(true, expectedEtag.equals(objectMetadata.getETag()));
}
assertNotNull(objectMetadata.getLastModified());
return objectMetadata;
}
Aggregations