File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed
src/main/java/com/qcloud/cos/demo Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff 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" );
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments