生活随笔
收集整理的這篇文章主要介紹了
阿里云创建及管理bucket(二)
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
存儲(chǔ)空間的創(chuàng)建及管理(二)
管理存儲(chǔ)空間訪問權(quán)限(ALI)
獲取訪問權(quán)限:
getBucketAcl(String bucketName)
輸入?yún)?shù) :bucketNmae
public String
getBucketAcl(String bucketName
){OSS ossClient
= new OSSClientBuilder().build(endpoint
,accessKeyId
,accessKeySecret
);AccessControlList bucketAcl
= ossClient
.getBucketAcl(bucketName
);System
.out
.println(bucketAcl
.toString());ossClient
.shutdown();return bucketAcl
.toString();}
設(shè)置訪問權(quán)限:
setBucketAcl(String bucketName, int acl)
輸入?yún)?shù): bucketName
acl(int)1 : 私有 2:公共讀 3:公共讀寫
public String
setBucketAcl(String bucketName
, int acl
){OSS ossClient
= new OSSClientBuilder().build(endpoint
,accessKeyId
,accessKeySecret
);try{switch (acl
){case 1:ossClient
.setBucketAcl(bucketName
,CannedAccessControlList
.Private
);break;case 2:ossClient
.setBucketAcl(bucketName
, CannedAccessControlList
.PublicRead
);break;case 3:ossClient
.setBucketAcl(bucketName
, CannedAccessControlList
.PublicReadWrite
);break;}} catch (OSSException e
) {e
.printStackTrace();return "false";} catch (ClientException e
) {e
.printStackTrace();return "false";}ossClient
.shutdown();return "設(shè)置存儲(chǔ)空間訪問權(quán)限成功";}
刪除存儲(chǔ)空間
deleteBucket(String bucketName)
public String
deleteBucket(String bucketName
){OSS ossClient
= new OSSClientBuilder().build(endpoint
,accessKeyId
,accessKeySecret
);try {ossClient
.deleteBucket(bucketName
);} catch (OSSException e
) {e
.printStackTrace();return "false";} catch (ClientException e
) {e
.printStackTrace();return "false";}ossClient
.shutdown();return "刪除存儲(chǔ)空間成功";}
管理存儲(chǔ)標(biāo)簽
設(shè)置存儲(chǔ)標(biāo)簽:
setBucketTagging(String bucketName, String tagKey, String tagValue)
輸入?yún)?shù):bucketName
tagKey 標(biāo)簽鍵
tagValue 標(biāo)簽值
public String
setBucketTagging(String bucketName
, String tagKey
, String tagValue
){OSS ossClient
= new OSSClientBuilder().build(endpoint
,accessKeyId
,accessKeySecret
);try {SetBucketTaggingRequest request
= new SetBucketTaggingRequest(bucketName
);request
.setTag(tagKey
,tagValue
);ossClient
.setBucketTagging(request
);} catch (OSSException e
) {e
.printStackTrace();return "false";} catch (ClientException e
) {e
.printStackTrace();return "false";}ossClient
.shutdown();return "設(shè)置標(biāo)簽成功";}
獲取存儲(chǔ)標(biāo)簽(Map)
Map<String,String> getBucketTagging(String bucketName)
返回一個(gè)包含所有tag的Map集合
public Map
<String,String> getBucketTagging(String bucketName
){OSS ossClient
= new OSSClientBuilder().build(endpoint
,accessKeyId
,accessKeySecret
);TagSet tagSet
= ossClient
.getBucketTagging(new GenericRequest(bucketName
));Map
<String,String> tags
= tagSet
.getAllTags();ossClient
.shutdown();return tags
;}
列舉帶有指定標(biāo)簽的bucket
List listBucketByTag(String tagKey, String tagValue)
輸入?yún)?shù):tagKey:標(biāo)簽鍵
tagValue: 標(biāo)簽值
返回結(jié)果:
符合標(biāo)簽的bucket列表
public List
<Bucket> listBucketByTag(String tagKey
, String tagValue
){OSS ossClient
= new OSSClientBuilder().build(endpoint
, accessKeyId
, accessKeySecret
);ListBucketsRequest listBucketsRequest
= new ListBucketsRequest();listBucketsRequest
.setTag(tagKey
,tagValue
);BucketList bucketList
= ossClient
.listBuckets(listBucketsRequest
);for (Bucket bucket
: bucketList
.getBucketList()){System
.out
.println("list result bucket: " + bucket
.getName());}ossClient
.shutdown();return bucketList
.getBucketList();}
刪除bucket標(biāo)簽
deleteBucketTagging(String bucketName)
public String
deleteBucketTagging(String bucketName
){OSS ossClient
= new OSSClientBuilder().build(endpoint
, accessKeyId
, accessKeySecret
);ossClient
.deleteBucketTagging(new GenericRequest(bucketName
));ossClient
.shutdown();return "成功刪除標(biāo)簽";}
管理存儲(chǔ)清單(ALI)
添加存儲(chǔ)清單配置
setBucketInventoryConfiguration(String bucketName,String inventoryId, int inventoryFrequency,
int InventoryIncludedObjectVersions,int isEnabled,
String objPrefix, String destinationPrefix,
int bucketFormat, String accountId,
String roleArn, String destBucketName
)
輸入?yún)?shù):bucketName 當(dāng)前bucket名稱
// inventoryId 存儲(chǔ)空間清單Id
// inventoryFrequency 清單生成頻率 1:Weekly 2:Daily
// InventoryIncludedObjectVersions 清單包含對(duì)象版本:1當(dāng)前版本 2歷史版本
// isEnabled 是否啟用存儲(chǔ)清單: 0:關(guān)閉 1:啟動(dòng)
// objPrefix 搜索包含該前綴的對(duì)象
// destinationPrefix 清單存儲(chǔ)路徑前綴
// bucketFormat 清單格式 1:CSV(只有這一種格式)
// accountId 目的地bucket的用戶accountId
// roleArn 目的地bucket的roleArn
// destBucketName 目的地bucket的名稱
public String
setBucketInventoryConfiguration(String bucketName
,String inventoryId
, int inventoryFrequency
,int InventoryIncludedObjectVersions
,int isEnabled
,String objPrefix
, String destinationPrefix
,int bucketFormat
, String accountId
,String roleArn
, String destBucketName
){OSS ossClient
= new OSSClientBuilder().build(endpoint
,accessKeyId
,accessKeySecret
);InventoryConfiguration inventoryConfiguration
= new InventoryConfiguration();inventoryConfiguration
.setInventoryId(inventoryId
);List
<String> fields
= new ArrayList<String>();fields
.add(InventoryOptionalFields
.Size
);fields
.add(InventoryOptionalFields
.LastModifiedDate
);fields
.add(InventoryOptionalFields
.IsMultipartUploaded
);fields
.add(InventoryOptionalFields
.StorageClass
);fields
.add(InventoryOptionalFields
.ETag
);fields
.add(InventoryOptionalFields
.EncryptionStatus
);inventoryConfiguration
.setOptionalFields(fields
);switch (inventoryFrequency
){case 1:inventoryConfiguration
.setSchedule(new InventorySchedule().withFrequency(InventoryFrequency
.Weekly
));break;case 2:inventoryConfiguration
.setSchedule(new InventorySchedule().withFrequency(InventoryFrequency
.Daily
));break;}switch (isEnabled
){case 0:inventoryConfiguration
.setEnabled(false);break;case 1:inventoryConfiguration
.setEnabled(true);break;}InventoryFilter inventoryFilter
= new InventoryFilter();inventoryFilter
.withPrefix(objPrefix
);inventoryConfiguration
.setInventoryFilter(inventoryFilter
);InventoryOSSBucketDestination ossInvDest
= new InventoryOSSBucketDestination();ossInvDest
.setPrefix(destinationPrefix
);if(bucketFormat
==1)ossInvDest
.setFormat(InventoryFormat
.CSV
);ossInvDest
.setAccountId(accountId
);ossInvDest
.setRoleArn(roleArn
);ossInvDest
.setBucket(destBucketName
);InventoryDestination destination
= new InventoryDestination();destination
.setOssBucketDestination(ossInvDest
);inventoryConfiguration
.setDestination(destination
);ossClient
.setBucketInventoryConfiguration(bucketName
, inventoryConfiguration
);ossClient
.shutdown();return "創(chuàng)建清單配置成功";}
總結(jié)
以上是生活随笔為你收集整理的阿里云创建及管理bucket(二)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。