刪除值區

本頁說明如何刪除 Cloud Storage 值區。如需值區總覽,請參閱重要詞彙

刪除值區:

主控台

  1. 在 Google Cloud Platform Console 中開啟 Cloud Storage 瀏覽器。
    開啟 Cloud Storage 瀏覽器
  2. 找到您要刪除的值區,並選取旁邊的核取方塊。

  3. 按一下 [Delete] (刪除)。

  4. 在出現的重疊視窗中,確認您要刪除的值區及內容,然後按一下 [Delete] (刪除)

gsutil

使用加上 -r 旗標的 gsutil rm 指令:

gsutil rm -r gs://[BUCKET_NAME]

其中 [BUCKET_NAME] 是要刪除的值區名稱。例如,my-bucket

回應類似下列範例:

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 來透過 DELETE 值區要求呼叫 JSON API

    curl -X DELETE -H "Authorization: Bearer [OAUTH2_TOKEN]" \
      "https://www.googleapis.com/storage/v1/b/[BUCKET_NAME]"

    其中:

    • [OAUTH2_TOKEN] 是您在步驟 1 產生的存取憑證。
    • [BUCKET_NAME] 是要刪除的值區名稱。例如,my-bucket

如果成功,回應會包含 204 狀態碼。

XML API

  1. OAuth 2.0 Playground 取得授權存取憑證。將 Playground 設為使用自己的 OAuth 憑證。
  2. 使用 cURL 來透過 DELETE 值區要求呼叫 XML API

    curl -X DELETE -H "Authorization: Bearer [OAUTH2_TOKEN]" \
      "https://storage.googleapis.com/[BUCKET_NAME]"

    其中:

    • [OAUTH2_TOKEN] 是您在步驟 1 產生的存取憑證。
    • [BUCKET_NAME] 是要刪除的值區名稱。例如,my-bucket

後續步驟

本頁內容對您是否有任何幫助?請提供意見:

傳送您對下列選項的寶貴意見...

這個網頁
Cloud Storage
需要協助嗎?請前往我們的支援網頁