日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

阿里云创建及管理bucket(二)

發(fā)布時間:2023/12/14 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 阿里云创建及管理bucket(二) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

存儲空間的創(chuàng)建及管理(二)

  • 管理存儲空間訪問權(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){//輸入的acl只能是1 || 2 || 3OSS 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è)置存儲空間訪問權(quán)限成功";}
  • 刪除存儲空間
    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 "刪除存儲空間成功";}
  • 管理存儲標(biāo)簽
    設(shè)置存儲標(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)簽成功";}

    獲取存儲標(biāo)簽(Map)
    Map<String,String> getBucketTagging(String bucketName)
    返回一個包含所有tag的Map集合

    public Map<String,String> getBucketTagging(String bucketName){//輸入?yún)?shù):bucketName//返回結(jié)果:一個包含所有tag的Map集合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)簽";}
  • 管理存儲清單(ALI)
    添加存儲清單配置
    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 存儲空間清單Id
    // inventoryFrequency 清單生成頻率 1:Weekly 2:Daily
    // InventoryIncludedObjectVersions 清單包含對象版本:1當(dāng)前版本 2歷史版本
    // isEnabled 是否啟用存儲清單: 0:關(guān)閉 1:啟動
    // objPrefix 搜索包含該前綴的對象
    // destinationPrefix 清單存儲路徑前綴
    // 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){//輸入?yún)?shù):bucketName 當(dāng)前bucket名稱// inventoryId 存儲空間清單Id// inventoryFrequency 清單生成頻率 1:Weekly 2:Daily// InventoryIncludedObjectVersions 清單包含對象版本:1當(dāng)前版本 2歷史版本// isEnabled 是否啟用存儲清單: 0:關(guān)閉 1:啟動// objPrefix 搜索包含該前綴的對象// destinationPrefix 清單存儲路徑前綴// bucketFormat 清單格式 1:CSV(只有這一種格式)// accountId 目的地bucket的用戶accountId// roleArn 目的地bucket的roleArn// destBucketName 目的地bucket的名稱OSS ossClient = new OSSClientBuilder().build(endpoint,accessKeyId,accessKeySecret);//創(chuàng)建清單配置InventoryConfiguration inventoryConfiguration = new InventoryConfiguration();//設(shè)置清單配置IdinventoryConfiguration.setInventoryId(inventoryId);//設(shè)置清單包含object的屬性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);//設(shè)置清單生成頻率switch (inventoryFrequency){case 1:inventoryConfiguration.setSchedule(new InventorySchedule().withFrequency(InventoryFrequency.Weekly));break;case 2:inventoryConfiguration.setSchedule(new InventorySchedule().withFrequency(InventoryFrequency.Daily));break;}//設(shè)置清單配置是否啟用switch (isEnabled){case 0:inventoryConfiguration.setEnabled(false);break;case 1:inventoryConfiguration.setEnabled(true);break;}//設(shè)置清單篩選規(guī)則指定篩選object前綴InventoryFilter inventoryFilter = new InventoryFilter();inventoryFilter.withPrefix(objPrefix);inventoryConfiguration.setInventoryFilter(inventoryFilter);//創(chuàng)建清單的bucket目的地配置InventoryOSSBucketDestination ossInvDest = new InventoryOSSBucketDestination();// 設(shè)置產(chǎn)生清單結(jié)果的存儲路徑前綴。ossInvDest.setPrefix(destinationPrefix);// 設(shè)置清單格式。if(bucketFormat==1)ossInvDest.setFormat(InventoryFormat.CSV);// 目的地bucket的用戶accountId。ossInvDest.setAccountId(accountId);// 目的地bucket的roleArn。ossInvDest.setRoleArn(roleArn);// 目的地bucket的名稱。ossInvDest.setBucket(destBucketName);// 如果需要使用KMS加密清單,請參考如下設(shè)置。// InventoryEncryption inventoryEncryption = new InventoryEncryption();// InventoryServerSideEncryptionKMS serverSideKmsEncryption = new InventoryServerSideEncryptionKMS().withKeyId("test-kms-id");// inventoryEncryption.setServerSideKmsEncryption(serverSideKmsEncryption);// ossInvDest.setEncryption(inventoryEncryption);// 如果需要使用OSS服務(wù)端加密清單,請參考如下設(shè)置。// InventoryEncryption inventoryEncryption = new InventoryEncryption();// inventoryEncryption.setServerSideOssEncryption(new InventoryServerSideEncryptionOSS());// ossInvDest.setEncryption(inventoryEncryption);// 設(shè)置清單的目的地。InventoryDestination destination = new InventoryDestination();destination.setOssBucketDestination(ossInvDest);inventoryConfiguration.setDestination(destination);// 上傳清單配置。ossClient.setBucketInventoryConfiguration(bucketName, inventoryConfiguration);// 關(guān)閉ossClient。ossClient.shutdown();return "創(chuàng)建清單配置成功";}

    總結(jié)

    以上是生活随笔為你收集整理的阿里云创建及管理bucket(二)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。