Skip to content

Commit 95b494e

Browse files
author
jeffreykzli
committed
update head obj Demo
1 parent 44df5b3 commit 95b494e

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/main/java/com/qcloud/cos/demo/GetObjectMetadataDemo.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ public static void main(String[] args) {
1313
getObjectMetadataDemo();
1414
}
1515

16-
// 将本地文件上传到COS
1716
private static void getObjectMetadataDemo() {
1817
// 1 初始化用户身份信息(secretId, secretKey)
1918
COSCredentials cred = new BasicCOSCredentials("AKIDXXXXXXXX", "1A2Z3YYYYYYYYYY");
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.qcloud.cos.demo;
2+
3+
import com.qcloud.cos.COSClient;
4+
import com.qcloud.cos.ClientConfig;
5+
import com.qcloud.cos.auth.BasicCOSCredentials;
6+
import com.qcloud.cos.auth.COSCredentials;
7+
import com.qcloud.cos.region.Region;
8+
9+
public class HeadObjectDemo {
10+
public static void main(String[] args) {
11+
headObject();
12+
}
13+
14+
private static void headObject() {
15+
// 1 初始化用户身份信息(secretId, secretKey)
16+
COSCredentials cred = new BasicCOSCredentials("AKIDXXXXXXXX", "1A2Z3YYYYYYYYYY");
17+
// 2 设置bucket的区域, COS地域的简称请参照 https://www.qcloud.com/document/product/436/6224
18+
ClientConfig clientConfig = new ClientConfig(new Region("ap-beijing-1"));
19+
// 3 生成cos客户端
20+
COSClient cosclient = new COSClient(cred, clientConfig);
21+
// bucket名需包含appid
22+
String bucketName = "mybucket-12500000000";
23+
24+
String key = "aaa/bbb.txt";
25+
boolean is_exist = cosclient.doesObjectExist(bucketName, key);
26+
System.out.println(is_exist);
27+
// 关闭客户端
28+
cosclient.shutdown();
29+
}
30+
}

0 commit comments

Comments
 (0)