日本熟妇hd丰满老熟妇,中文字幕一区二区三区在线不卡 ,亚洲成片在线观看,免费女同在线一区二区

刪除Object

重要

本文中含有需要您注意的重要提示信息,忽略該信息可能對您的業務造成影響,請務必仔細閱讀。

您可以通過多種方式刪除云盒Bucket中不再需要保留的文件(Object)。

警告

Object刪除后無法恢復,請在刪除前確認Object已不再使用,請您謹慎操作。

刪除規則

OSS支持手動或者自動刪除單個或多個Object,刪除規則說明如下:

  • 手動刪除

    • 刪除單個Object

      您可以通過SDK、命令行工具ossutil的方式刪除單個Object。

    • 刪除多個Object

      通過SDK一次最多可刪除1000Object,通過命令行工具ossutil一次最多可刪除的Object個數無限制。

  • 自動刪除

    如果需要刪除的Object數目較多,且刪除的Object有一定的規律,例如需要定期刪除指定日期之前的Object,指定前綴的Object,又或者需要清空整個Bucket內的所有Object。此時,推薦您配置生命周期規則自動刪除Object。生命周期規則配置完成后,OSS會根據規則自動刪除指定Object,從而減少您發送刪除請求的次數,以提高刪除效率。更多信息,請參見生命周期規則

刪除單個Object

使用Java SDK

僅支持通過Java SDK刪除多個Object,Java SDK要求3.15.0及以上版本。

import com.aliyun.oss.ClientException;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.OSSException;
import com.aliyun.oss.common.auth.DefaultCredentialProvider;
import com.aliyun.oss.common.comm.SignVersion;
import com.aliyun.oss.ClientBuilderConfiguration;
import com.aliyun.oss.common.auth.CredentialsProviderFactory;
import com.aliyun.oss.common.auth.EnvironmentVariableCredentialsProvider;

public class Demo {
    public static void main(String[] args) throws Exception {
        // 填寫云盒所在地域對應的Endpoint。
        String endpoint = "https://cb-f8z7yvzgwfkl9q0h****.cn-hangzhou.oss-cloudbox.aliyuncs.com";
        // 從環境變量中獲取訪問憑證。運行本代碼示例之前,請確保已設置環境變量OSS_ACCESS_KEY_ID和OSS_ACCESS_KEY_SECRET。
        EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
        // 填寫云盒Bucket名稱,例如examplebucket。
        String bucketName = "examplebucket";
        // 填寫云盒Bucket所在地域。
        String region = "cn-hangzhou";
        // 填寫云盒ID。
        String cloudBoxId = "cb-f8z7yvzgwfkl9q0h****";
        // 填寫Object完整路徑,完整路徑中不能包含Bucket名稱。
        String objectName = "exampleobject.txt";

        // 創建OSSClient實例。
        ClientBuilderConfiguration conf = new ClientBuilderConfiguration();
        conf.setSignatureVersion(SignVersion.V4);
        OSS ossClient = OSSClientBuilder.create()
                .endpoint(endpoint)
                .credentialsProvider(new DefaultCredentialProvider(credentialsProvider.getCredentials()))
                .clientConfiguration(conf)
                .region(region)
                .cloudBoxId(cloudBoxId)
                .build();

        try {
            // 刪除文件或目錄。如果要刪除目錄,目錄必須為空。
            ossClient.deleteObject(bucketName, objectName);
        } catch (OSSException oe) {
            System.out.println("Caught an OSSException, which means your request made it to OSS, "
                    + "but was rejected with an error response for some reason.");
            System.out.println("Error Message:" + oe.getErrorMessage());
            System.out.println("Error Code:" + oe.getErrorCode());
            System.out.println("Request ID:" + oe.getRequestId());
            System.out.println("Host ID:" + oe.getHostId());
        } catch (ClientException ce) {
            System.out.println("Caught an ClientException, which means the client encountered "
                    + "a serious internal problem while trying to communicate with OSS, "
                    + "such as not being able to access the network.");
            System.out.println("Error Message:" + ce.getMessage());
        } finally {
            if (ossClient != null) {
                ossClient.shutdown();
            }
        }
    }
}            

使用命令行工具ossutil

關于使用ossutil刪除單個Object的具體操作,請參見刪除Object

使用REST API

如果您的程序自定義要求較高,您可以直接發起REST API請求。直接發起REST API請求需要手動編寫代碼計算簽名。

關于刪除單個ObjectAPI接口說明,請參見DeleteObject

刪除多個Object

使用Java SDK

僅支持通過Java SDK刪除多個Object,Java SDK要求3.15.0及以上版本。

import com.aliyun.oss.ClientException;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.OSSException;
import com.aliyun.oss.model.DeleteObjectsRequest;
import com.aliyun.oss.model.DeleteObjectsResult;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.List;
import com.aliyun.oss.common.auth.DefaultCredentialProvider;
import com.aliyun.oss.common.auth.CredentialsProviderFactory;
import com.aliyun.oss.common.auth.EnvironmentVariableCredentialsProvider;
import com.aliyun.oss.common.comm.SignVersion;
import com.aliyun.oss.ClientBuilderConfiguration;


public class Demo {
    public static void main(String[] args) throws Exception {
        // 填寫云盒所在地域對應的Endpoint。
        String endpoint = "https://cb-f8z7yvzgwfkl9q0h****.cn-hangzhou.oss-cloudbox.aliyuncs.com";
        // 從環境變量中獲取訪問憑證。運行本代碼示例之前,請確保已設置環境變量OSS_ACCESS_KEY_ID和OSS_ACCESS_KEY_SECRET。
        EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
        // 填寫云盒Bucket名稱,例如examplebucket。
        String bucketName = "examplebucket";
        // 填寫云盒Bucket所在地域。
        String region = "cn-hangzhou";
        // 填寫云盒ID。
        String cloudBoxId = "cb-f8z7yvzgwfkl9q0h****";

        // 創建OSSClient實例。
        ClientBuilderConfiguration conf = new ClientBuilderConfiguration();
        conf.setSignatureVersion(SignVersion.V4);
        OSS ossClient = OSSClientBuilder.create()
                .endpoint(endpoint)
                .credentialsProvider(new DefaultCredentialProvider(credentialsProvider.getCredentials()))
                .clientConfiguration(conf)
                .region(region)
                .cloudBoxId(cloudBoxId)
                .build();

        try {
            // 刪除多個Object。
            // 填寫需要刪除的多個Object完整路徑,完整路徑中不能包含Bucket名稱。
            List<String> keys = new ArrayList<String>();
            keys.add("exampleobjecta.txt");
            keys.add("testfolder/sampleobject.txt");
            keys.add("exampleobjectb.txt");

            DeleteObjectsResult deleteObjectsResult = ossClient.deleteObjects(new DeleteObjectsRequest(bucketName).withKeys(keys).withEncodingType("url"));
            List<String> deletedObjects = deleteObjectsResult.getDeletedObjects();
            try {
                for(String obj : deletedObjects) {
                    String deleteObj =  URLDecoder.decode(obj, "UTF-8");
                    System.out.println(deleteObj);
                }
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        } catch (OSSException oe) {
            System.out.println("Caught an OSSException, which means your request made it to OSS, "
                    + "but was rejected with an error response for some reason.");
            System.out.println("Error Message:" + oe.getErrorMessage());
            System.out.println("Error Code:" + oe.getErrorCode());
            System.out.println("Request ID:" + oe.getRequestId());
            System.out.println("Host ID:" + oe.getHostId());
        } catch (ClientException ce) {
            System.out.println("Caught an ClientException, which means the client encountered "
                    + "a serious internal problem while trying to communicate with OSS, "
                    + "such as not being able to access the network.");
            System.out.println("Error Message:" + ce.getMessage());
        } finally {
            if (ossClient != null) {
                ossClient.shutdown();
            }
        }
    }
}      
                

使用命令行工具ossutil

關于使用ossutil刪除多個Object的具體操作,請參見刪除Object

使用REST API

如果您的程序自定義要求較高,您可以直接發起REST API請求。直接發起REST API請求需要手動編寫代碼計算簽名。

關于刪除多個ObjectAPI接口說明,請參見DeleteMultipleObjects