1212import com .qcloud .cos .region .Region ;
1313
1414public class ModifyObjectMetadataDemo {
15+ private static String secretId = System .getenv ("SECRETID" );
16+ private static String secretKey = System .getenv ("SECRETKEY" );
17+ private static String bucketName = System .getenv ("BUCKET_NAME" );
18+ private static String region = System .getenv ("REGION" );
1519 public static void main (String [] args ) {
1620 // 1 初始化用户身份信息(secretId, secretKey)
17- COSCredentials cred = new BasicCOSCredentials ("AKIDXXXXXXXX" , "1A2Z3YYYYYYYYYY" );
21+ COSCredentials cred = new BasicCOSCredentials (secretId , secretKey );
1822 // 2 设置bucket的区域, COS地域的简称请参照 https://www.qcloud.com/document/product/436/6224
19- Region region = new Region ("ap-beijing" );
20- ClientConfig clientConfig = new ClientConfig (region );
23+ Region cosRegion = new Region (region );
24+ ClientConfig clientConfig = new ClientConfig (cosRegion );
2125 // 3 生成cos客户端
2226 COSClient cosclient = new COSClient (cred , clientConfig );
2327
24- // 存储桶的命名格式为 BucketName-APPID,此处填写的存储桶名称必须为此格式
25- String bucketName = "examplebucket-1250000000" ;
2628 String key = "exampleobject" ;
2729
2830 ObjectMetadata objectMetadata = cosclient .getObjectMetadata (bucketName , key );
@@ -33,7 +35,7 @@ public static void main(String[] args) {
3335 objectMetadata .setHeader ("x-cos-storage-class" , "STANDARD_IA" );
3436 objectMetadata .setContentType ("text/plain" );
3537
36- CopyObjectRequest copyObjectRequest = new CopyObjectRequest (region , bucketName , key , bucketName , key );
38+ CopyObjectRequest copyObjectRequest = new CopyObjectRequest (cosRegion , bucketName , key , bucketName , key );
3739 copyObjectRequest .setNewObjectMetadata (objectMetadata );
3840
3941 try {
0 commit comments