use of com.qcloud.cos.model.ObjectMetadata in project cos-java-sdk-v5 by tencentyun.
the class PutObjectDemo method putObjectDemo.
static void putObjectDemo() {
String bucketName = "examplebucket-1251668577";
String key = "abc/abc.txt";
String localPath = "abc.txt";
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setHeader("expires", new Date(1660000000000L));
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key, new File(localPath));
putObjectRequest.withMetadata(objectMetadata);
PutObjectResult putObjectResult = cosClient.putObject(putObjectRequest);
System.out.println(putObjectResult.getRequestId());
GetObjectRequest getObjectRequest = new GetObjectRequest(bucketName, key);
COSObject cosObject = cosClient.getObject(getObjectRequest);
System.out.println(cosObject.getObjectMetadata().getRequestId());
cosClient.shutdown();
}
use of com.qcloud.cos.model.ObjectMetadata in project cos-java-sdk-v5 by tencentyun.
the class BucketTaggingDemo method SetTagWhilePutObject.
public static void SetTagWhilePutObject() {
// 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-shanghai"));
// 3 生成cos客户端
COSClient cosclient = new COSClient(cred, clientConfig);
// bucket名需包含appid
String bucketName = "mybucket-1251668577";
String key = "testTag";
InputStream is = new ByteArrayInputStream(new byte[] { 'd', 'a', 't', 'a' });
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setHeader("x-cos-tagging", "level=info");
cosclient.putObject(bucketName, key, is, objectMetadata);
}
use of com.qcloud.cos.model.ObjectMetadata in project cos-java-sdk-v5 by tencentyun.
the class PicOperationDemo method PicPersistentProcessing.
public static void PicPersistentProcessing() {
// 1 初始化用户身份信息(secretId, secretKey)
COSCredentials cred = new BasicCOSCredentials("SECRET_ID", "SECRET_KEY");
// 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);
// 4. bucket名需包含appid
String bucketName = "examplebucket-1250000000";
String key = "example.jpg";
File localFile = new File("/data/example.jpg");
// 5.对图像进行持久化处理
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setHeader("Pic-Operations", "{\"is_pic_info\":1,\"rules\":[{\"fileid\":\"example.png\",\"rule\":\"imageView2/format/png\"}]}");
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key, localFile);
putObjectRequest.setMetadata(objectMetadata);
try {
PutObjectResult putObjectResult = cosclient.putObject(putObjectRequest);
// putobjectResult会返回文件的etag
String etag = putObjectResult.getETag();
} catch (CosServiceException e) {
e.printStackTrace();
} catch (CosClientException e) {
e.printStackTrace();
}
// 关闭客户端
cosclient.shutdown();
}
use of com.qcloud.cos.model.ObjectMetadata in project cos-java-sdk-v5 by tencentyun.
the class PutObjectCopyTest method testUpdateDiffSize.
private void testUpdateDiffSize(long fileSize, ObjectMetadata newObjectMetaData) throws IOException {
if (!judgeUserInfoValid()) {
return;
}
File localFile = buildTestFile(fileSize);
String srcEtag = Md5Utils.md5Hex(localFile);
String srcKey = String.format("ut/src_len_%d.txt", fileSize);
try {
putObjectFromLocalFile(localFile, srcKey);
cosclient.updateObjectMetaData(bucket, srcKey, newObjectMetaData);
ObjectMetadata destObjectMetadata = headSimpleObject(srcKey, fileSize, srcEtag);
if (newObjectMetaData != null) {
checkMetaData(newObjectMetaData, destObjectMetadata);
}
} finally {
// delete file on cos
clearObject(srcKey);
// delete local file
if (localFile.exists()) {
assertTrue(localFile.delete());
}
}
}
use of com.qcloud.cos.model.ObjectMetadata in project cos-java-sdk-v5 by tencentyun.
the class PutObjectCopyTest method testCopySameRegionEmptyWithNewMetaData.
@Test
public void testCopySameRegionEmptyWithNewMetaData() throws IOException {
ObjectMetadata newObjectMetadata = new ObjectMetadata();
newObjectMetadata.setServerSideEncryption("AES256");
newObjectMetadata.setContentType("image/tiff");
testCopySameRegionDiffSize(0, newObjectMetadata);
}
Aggregations