删除存储分区

本页面显示了如何删除 Cloud Storage 存储分区。如需查看存储分区的概览,请参阅关键术语

要删除存储分区,请执行以下操作:

Console

  1. 在 Google Cloud Platform Console 中打开 Cloud Storage 浏览器。
    打开 Cloud Storage 浏览器
  2. 选中与要删除的存储分区对应的复选框。

  3. 点击删除

  4. 在出现的叠加窗口中,点击删除以确认要删除此存储分区及其内容。

gsutil

使用带有 -r 标志的 gsutil rm 命令,并将 [VALUES_IN_BRACKETS] 替换为适当的值:

gsutil rm -r gs://[BUCKET_NAME]

响应类似于以下示例:

Removing gs://[BUCKET_NAME]/...

代码示例

C++

如需了解详情,请参阅 Cloud Storage C++ API 参考文档

namespace gcs = google::cloud::storage;
[](gcs::Client client, std::string bucket_name) {
  google::cloud::Status status = client.DeleteBucket(bucket_name);

  if (!status.ok()) {
    throw std::runtime_error(status.message());
  }

  std::cout << "The bucket " << bucket_name << " was deleted successfully.\n";
}

C#

如需了解详情,请参阅 Cloud Storage C# API 参考文档

private void DeleteBucket(string bucketName)
{
    var storage = StorageClient.Create();
    storage.DeleteBucket(bucketName);
    Console.WriteLine($"Deleted {bucketName}.");
}

Go

如需了解详情,请参阅 Cloud Storage Go API 参考文档

if err := client.Bucket(bucketName).Delete(ctx); err != nil {
	return err
}

Java

如需了解详情,请参阅 Cloud Storage Java API 参考文档

boolean deleted = bucket.delete(BucketSourceOption.metagenerationMatch());
if (deleted) {
  // the bucket was deleted
} else {
  // the bucket was not found
}

Node.js

如需了解详情,请参阅 Cloud Storage Node.js API 参考文档

// Imports the Google Cloud client library
const {Storage} = require('@google-cloud/storage');

// Creates a client
const storage = new Storage();

/**
 * TODO(developer): Uncomment the following line before running the sample.
 */
// const bucketName = 'Name of a bucket, e.g. my-bucket';

// Deletes the bucket
await storage.bucket(bucketName).delete();

console.log(`Bucket ${bucketName} deleted.`);

PHP

如需了解详情,请参阅 Cloud Storage PHP API 参考文档

use Google\Cloud\Storage\StorageClient;

/**
 * Delete a Cloud Storage Bucket.
 *
 * @param string $bucketName the name of the bucket to delete.
 *
 * @return void
 */
function delete_bucket($bucketName)
{
    $storage = new StorageClient();
    $bucket = $storage->bucket($bucketName);
    $bucket->delete();
    printf('Bucket deleted: %s' . PHP_EOL, $bucket->name());
}

Python

如需了解详情,请参阅 Cloud Storage Python API 参考文档

def delete_bucket(bucket_name):
    """Deletes a bucket. The bucket must be empty."""
    storage_client = storage.Client()
    bucket = storage_client.get_bucket(bucket_name)
    bucket.delete()
    print('Bucket {} deleted'.format(bucket.name))

Ruby

如需了解详情,请参阅 Cloud Storage Ruby API 参考文档

# project_id  = "Your Google Cloud project ID"
# bucket_name = "Name of your Google Cloud Storage bucket to delete"

require "google/cloud/storage"

storage = Google::Cloud::Storage.new project_id: project_id
bucket  = storage.bucket bucket_name

bucket.delete

puts "Deleted bucket: #{bucket.name}"

REST API

JSON API

请注意,您必须先清空存储分区,然后才能将其删除。

  1. OAuth 2.0 Playground 获取授权访问令牌。将 Playground 配置为使用您自己的 OAuth 凭据。
  2. 使用 cURL 调用 JSON API,将 [VALUES_IN_BRACKETS] 替换为适当的值:
    curl -X DELETE -H "Authorization: Bearer [OAUTH2_TOKEN]" \
        "https://www.googleapis.com/storage/v1/b/[BUCKET_NAME]"

如果成功,响应将包含 204 状态代码。

有关详情,请参阅存储分区:删除 JSON 参考页面。

XML API

请注意,您必须先清空存储分区,然后才能将其删除。

  1. OAuth 2.0 Playground 获取授权访问令牌。将 Playground 配置为使用您自己的 OAuth 凭据。
  2. 使用 cURL 调用 XML API,将 [VALUES_IN_BRACKETS] 替换为适当的值:
    curl -X DELETE -H "Authorization: Bearer [OAUTH2_TOKEN]" \
        "https://storage.googleapis.com/[BUCKET_NAME]"

有关详情,请参阅删除存储分区 XML 参考页面。

后续步骤

此页内容是否有用?请给出您的反馈和评价:

发送以下问题的反馈:

此网页
Cloud Storage
需要帮助?请访问我们的支持页面