删除Bucket
更新时间:2022-10-21
基本流程
- 创建BOSClient类的实例。
- 执行BOSClient.deleteBucket()方法。
- deleteBucket()无返回值,删除失败时会抛出异常。
示例代码
client.deleteBucket(<BucketName>); //指定Bucket名称
注意:如果Bucket不为空(即Bucket中有Object和未完成的三步上传Part存在),则Bucket无法被删除,必须清空Bucket后才能成功删除。
完整示例
import android.app.Activity;
import android.os.Bundle;
import com.baidubce.BceClientException;
import com.baidubce.BceServiceException;
import com.baidubce.auth.DefaultBceCredentials;
import com.baidubce.development.R;
import com.baidubce.services.bos.BosClient;
import com.baidubce.services.bos.BosClientConfiguration;
public class ExampleActivity extends Activity {
private String bucketName = <BucketName>;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new Thread(new Runnable() {
@Override
public void run() {
try {
BosClientConfiguration config = new BosClientConfiguration();
config.setCredentials(new DefaultBceCredentials(<AccessKeyID>, <SecretAccessKey>));
config.setEndpoint(<EndPoint>);
BosClient client = new BosClient(config);
// 删除Bucket
client.deleteBucket(<BucketName>); //指定Bucket名称
} catch (BceServiceException e) {
System.out.println("Error ErrorCode: " + e.getErrorCode());
System.out.println("Error RequestId: " + e.getRequestId());
System.out.println("Error StatusCode: " + e.getStatusCode());
System.out.println("Error Message: " + e.getMessage());
System.out.println("Error ErrorType: " + e.getErrorType());
} catch (BceClientException e) {
System.out.println("Error Message: " + e.getMessage());
}
}
}).start();
}
}