๊ฐ์ฒด ์‚ญ์ œ

์ด ํŽ˜์ด์ง€๋Š” Cloud Storage์˜ ๋ฒ„ํ‚ท์—์„œ ๊ฐ์ฒด๋ฅผ ์‚ญ์ œํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์„ค๋ช…ํ•ฉ๋‹ˆ๋‹ค.

ํ•„์š”ํ•œ ์—ญํ• 

๊ฐ์ฒด๋ฅผ ์‚ญ์ œํ•˜๋Š” ๋ฐ ํ•„์š”ํ•œ ๊ถŒํ•œ์„ ์–ป์œผ๋ ค๋ฉด ๊ด€๋ฆฌ์ž์—๊ฒŒ ์‚ญ์ œํ•  ๊ฐ์ฒด๊ฐ€ ํฌํ•จ๋œ ๋ฒ„ํ‚ท์— ๋Œ€ํ•œ ์Šคํ† ๋ฆฌ์ง€ ๊ฐ์ฒด ์‚ฌ์šฉ์ž(roles/storage.objectUser) IAM ์—ญํ• ์„ ๋ถ€์—ฌํ•ด๋‹ฌ๋ผ๊ณ  ์š”์ฒญํ•˜์„ธ์š”.

Google Cloud ์ฝ˜์†”์„ ์‚ฌ์šฉํ•˜์—ฌ ์ด ํŽ˜์ด์ง€์˜ ํƒœ์Šคํฌ๋ฅผ ์™„๋ฃŒํ•˜๋ ค๋ฉด ๊ด€๋ฆฌ์ž์—๊ฒŒ ์Šคํ† ๋ฆฌ์ง€ ๊ฐ์ฒด ์‚ฌ์šฉ์ž(roles/storage.objectUser) ์—ญํ•  ๋Œ€์‹  ์Šคํ† ๋ฆฌ์ง€ ๊ด€๋ฆฌ์ž(roles/storage.admin) ์—ญํ• ์„ ๋ถ€์—ฌํ•˜๊ฑฐ๋‚˜ ์Šคํ† ๋ฆฌ์ง€ ๊ฐ์ฒด ์‚ฌ์šฉ์ž(roles/storage.objectUser) ์—ญํ•  ์™ธ์— ๋ทฐ์–ด(roles/viewer) ๊ธฐ๋ณธ ์—ญํ• ์„ ๋ถ€์—ฌํ•ด๋‹ฌ๋ผ๊ณ  ์š”์ฒญํ•˜์„ธ์š”.

์ด๋Ÿฌํ•œ ์—ญํ• ์—๋Š” ๊ฐ์ฒด๋ฅผ ์‚ญ์ œํ•˜๋Š” ๋ฐ ํ•„์š”ํ•œ ๊ถŒํ•œ์ด ํฌํ•จ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ํ•„์š”ํ•œ ์ •ํ™•ํ•œ ๊ถŒํ•œ์„ ๋ณด๋ ค๋ฉด ํ•„์š”ํ•œ ๊ถŒํ•œ ์„น์…˜์„ ํ™•์žฅํ•˜์„ธ์š”.

ํ•„์ˆ˜ ๊ถŒํ•œ

  • storage.objects.delete
  • storage.objects.list
    • ์ด ๊ถŒํ•œ์€ Google Cloud ์ฝ˜์†”์„ ์‚ฌ์šฉํ•  ๋•Œ ๋˜๋Š” Google Cloud CLI์—์„œ --recursive ํ”Œ๋ž˜๊ทธ ๋˜๋Š” ์™€์ผ๋“œ ์นด๋“œ๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ๋งŒ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.
  • storage.buckets.list
    • ์ด ๊ถŒํ•œ์€ Google Cloud ์ฝ˜์†”์„ ์‚ฌ์šฉํ•˜์—ฌ ์ด ํŽ˜์ด์ง€์˜ ์•ˆ๋‚ด๋ฅผ ์ˆ˜ํ–‰ํ•  ๋•Œ๋งŒ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

๋‹ค๋ฅธ ์‚ฌ์ „ ์ •์˜๋œ ์—ญํ• ์ด๋‚˜ ์ปค์Šคํ…€ ์—ญํ• ์„ ์‚ฌ์šฉํ•˜์—ฌ ์ด๋Ÿฌํ•œ ๊ถŒํ•œ์„ ์–ป์„ ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

๋ฒ„ํ‚ท์˜ ์—ญํ•  ๋ถ€์—ฌ์— ๋Œ€ํ•œ ์ž์„ธํ•œ ๋‚ด์šฉ์€ ๋ฒ„ํ‚ท์— IAM ์‚ฌ์šฉ์„ ์ฐธ์กฐํ•˜์„ธ์š”.

๊ฐ์ฒด ์‚ญ์ œ

Cloud Storage ๋ฒ„ํ‚ท ์ค‘ ํ•˜๋‚˜์—์„œ ๊ฐ์ฒด๋ฅผ ์‚ญ์ œํ•˜๋ ค๋ฉด ๋‹ค์Œ ๋‹จ๊ณ„๋ฅผ ์™„๋ฃŒํ•ฉ๋‹ˆ๋‹ค.

์ฝ˜์†”

  1. Google Cloud ์ฝ˜์†”์—์„œ Cloud Storage ๋ฒ„ํ‚ท ํŽ˜์ด์ง€๋กœ ์ด๋™ํ•ฉ๋‹ˆ๋‹ค.

    ๋ฒ„ํ‚ท์œผ๋กœ ์ด๋™

  2. ๋ฒ„ํ‚ท ๋ชฉ๋ก์—์„œ ์‚ญ์ œํ•˜๋ ค๋Š” ๊ฐ์ฒด๊ฐ€ ํฌํ•จ๋œ ๋ฒ„ํ‚ท ์ด๋ฆ„์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.

    ๊ฐ์ฒด ํƒญ์ด ์„ ํƒ๋œ ์ƒํƒœ๋กœ ๋ฒ„ํ‚ท ์„ธ๋ถ€์ •๋ณด ํŽ˜์ด์ง€๊ฐ€ ์—ด๋ฆฝ๋‹ˆ๋‹ค.

  3. ๊ฐ์ฒด(ํด๋”์— ์žˆ์„ ์ˆ˜ ์žˆ์Œ)๋กœ ์ด๋™ํ•ฉ๋‹ˆ๋‹ค.

  4. ์‚ญ์ œํ•  ๊ฐ์ฒด๋งˆ๋‹ค ์ฒดํฌ๋ฐ•์Šค๋ฅผ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.

    ํด๋”์˜ ์ฒดํฌ๋ฐ•์Šค๋ฅผ ํด๋ฆญํ•˜์—ฌ ํ•ด๋‹น ํด๋”์— ํฌํ•จ๋œ ๋ชจ๋“  ๊ฐ์ฒด๋ฅผ ์‚ญ์ œํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

  5. ์‚ญ์ œ ๋ฒ„ํŠผ์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.

  6. ํ‘œ์‹œ๋˜๋Š” ๋Œ€ํ™”์ƒ์ž์—์„œ ์‚ญ์ œ๋ฅผ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.

ํ•œ ๋ฒˆ์— ์—ฌ๋Ÿฌ ๊ฐ์ฒด๋ฅผ ์‚ญ์ œํ•˜๋Š” ๊ฒฝ์šฐ Google Cloud ์ฝ˜์†”์—์„œ ์•Œ๋ฆผ ์•„์ด์ฝ˜์„ ํด๋ฆญํ•˜์—ฌ ์‚ญ์ œ ์ง„ํ–‰ ์ƒํ™ฉ์„ ์ถ”์ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.Google Cloud ์ฝ˜์†”์€ ์ตœ๋Œ€ ์ˆ˜๋ฐฑ๋งŒ ๊ฐœ์˜ ๊ฐ์ฒด๋ฅผ ์ผ๊ด„ ์‚ญ์ œํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ ์‚ญ์ œ ์ž‘์—…์€ ๋ฐฑ๊ทธ๋ผ์šด๋“œ์—์„œ ์ˆ˜ํ–‰๋ฉ๋‹ˆ๋‹ค.

Google Cloud ์ฝ˜์†”์—์„œ ์‹คํŒจํ•œ Cloud Storage ์ž‘์—…์— ๋Œ€ํ•œ ์ž์„ธํ•œ ์˜ค๋ฅ˜ ์ •๋ณด๋ฅผ ๊ฐ€์ ธ์˜ค๋Š” ๋ฐฉ๋ฒ•์€ ๋ฌธ์ œ ํ•ด๊ฒฐ์„ ์ฐธ์กฐํ•˜์„ธ์š”.

๋ช…๋ น์ค„

Google Cloud CLI ๋ช…๋ น์–ด gcloud storage rm์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

gcloud storage rm gs://BUCKET_NAME/OBJECT_NAME

๊ฐ ํ•ญ๋ชฉ์˜ ์˜๋ฏธ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

  • BUCKET_NAME์€ ์‚ญ์ œํ•  ๊ฐ์ฒด๊ฐ€ ํฌํ•จ๋œ ๋ฒ„ํ‚ท์˜ ์ด๋ฆ„์ž…๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค๋ฉด my-bucket์ž…๋‹ˆ๋‹ค.
  • OBJECT_NAME์€ ์‚ญ์ œํ•  ๊ฐ์ฒด์˜ ์ด๋ฆ„์ž…๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค๋ฉด pets/dog.png์ž…๋‹ˆ๋‹ค.

์„ฑ๊ณตํ•˜๋ฉด ๋‹ค์Œ ์˜ˆ์‹œ์™€ ๋น„์Šทํ•œ ์‘๋‹ต์ด ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค.

Removing objects:
Removing gs://example-bucket/file.txt...
  Completed 1/1

ํด๋ผ์ด์–ธํŠธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ

C++

์ž์„ธํ•œ ๋‚ด์šฉ์€ Cloud Storage C++ API ์ฐธ์กฐ ๋ฌธ์„œ๋ฅผ ํ™•์ธํ•˜์„ธ์š”.

Cloud Storage์— ์ธ์ฆํ•˜๋ ค๋ฉด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ธฐ๋ณธ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ํด๋ผ์ด์–ธํŠธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์˜ ์ธ์ฆ ์„ค์ •์„ ์ฐธ์กฐํ•˜์„ธ์š”.

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

  if (!status.ok()) throw std::runtime_error(status.message());
  std::cout << "Deleted " << object_name << " in bucket " << bucket_name
            << "\n";
}

C#

์ž์„ธํ•œ ๋‚ด์šฉ์€ Cloud Storage C# API ์ฐธ์กฐ ๋ฌธ์„œ๋ฅผ ํ™•์ธํ•˜์„ธ์š”.

Cloud Storage์— ์ธ์ฆํ•˜๋ ค๋ฉด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ธฐ๋ณธ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ํด๋ผ์ด์–ธํŠธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์˜ ์ธ์ฆ ์„ค์ •์„ ์ฐธ์กฐํ•˜์„ธ์š”.


using Google.Cloud.Storage.V1;
using System;

public class DeleteFileSample
{
    public void DeleteFile(
        string bucketName = "your-unique-bucket-name",
        string objectName = "your-object-name")
    {
        var storage = StorageClient.Create();
        storage.DeleteObject(bucketName, objectName);
        Console.WriteLine($"Deleted {objectName}.");
    }
}

Go

์ž์„ธํ•œ ๋‚ด์šฉ์€ Cloud Storage Go API ์ฐธ์กฐ ๋ฌธ์„œ๋ฅผ ํ™•์ธํ•˜์„ธ์š”.

Cloud Storage์— ์ธ์ฆํ•˜๋ ค๋ฉด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ธฐ๋ณธ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ํด๋ผ์ด์–ธํŠธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์˜ ์ธ์ฆ ์„ค์ •์„ ์ฐธ์กฐํ•˜์„ธ์š”.

import (
	"context"
	"fmt"
	"io"
	"time"

	"cloud.google.com/go/storage"
)

// deleteFile removes specified object.
func deleteFile(w io.Writer, bucket, object string) error {
	// bucket := "bucket-name"
	// object := "object-name"
	ctx := context.Background()
	client, err := storage.NewClient(ctx)
	if err != nil {
		return fmt.Errorf("storage.NewClient: %w", err)
	}
	defer client.Close()

	ctx, cancel := context.WithTimeout(ctx, time.Second*10)
	defer cancel()

	o := client.Bucket(bucket).Object(object)

	// Optional: set a generation-match precondition to avoid potential race
	// conditions and data corruptions. The request to delete the file is aborted
	// if the object's generation number does not match your precondition.
	attrs, err := o.Attrs(ctx)
	if err != nil {
		return fmt.Errorf("object.Attrs: %w", err)
	}
	o = o.If(storage.Conditions{GenerationMatch: attrs.Generation})

	if err := o.Delete(ctx); err != nil {
		return fmt.Errorf("Object(%q).Delete: %w", object, err)
	}
	fmt.Fprintf(w, "Blob %v deleted.\n", object)
	return nil
}

Java

์ž์„ธํ•œ ๋‚ด์šฉ์€ Cloud Storage Java API ์ฐธ์กฐ ๋ฌธ์„œ๋ฅผ ํ™•์ธํ•˜์„ธ์š”.

Cloud Storage์— ์ธ์ฆํ•˜๋ ค๋ฉด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ธฐ๋ณธ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ํด๋ผ์ด์–ธํŠธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์˜ ์ธ์ฆ ์„ค์ •์„ ์ฐธ์กฐํ•˜์„ธ์š”.

import com.google.cloud.storage.Blob;
import com.google.cloud.storage.BlobId;
import com.google.cloud.storage.Storage;
import com.google.cloud.storage.StorageOptions;

public class DeleteObject {
  public static void deleteObject(String projectId, String bucketName, String objectName) {
    // The ID of your GCP project
    // String projectId = "your-project-id";

    // The ID of your GCS bucket
    // String bucketName = "your-unique-bucket-name";

    // The ID of your GCS object
    // String objectName = "your-object-name";

    Storage storage = StorageOptions.newBuilder().setProjectId(projectId).build().getService();
    Blob blob = storage.get(bucketName, objectName);
    if (blob == null) {
      System.out.println("The object " + objectName + " wasn't found in " + bucketName);
      return;
    }
    BlobId idWithGeneration = blob.getBlobId();
    // Deletes the blob specified by its id. When the generation is present and non-null it will be
    // specified in the request.
    // If versioning is enabled on the bucket and the generation is present in the delete request,
    // only the version of the object with the matching generation will be deleted.
    // If instead you want to delete the current version, the generation should be dropped by
    // performing the following.
    // BlobId idWithoutGeneration =
    //    BlobId.of(idWithGeneration.getBucket(), idWithGeneration.getName());
    // storage.delete(idWithoutGeneration);
    storage.delete(idWithGeneration);

    System.out.println("Object " + objectName + " was permanently deleted from " + bucketName);
  }
}

Node.js

์ž์„ธํ•œ ๋‚ด์šฉ์€ Cloud Storage Node.js API ์ฐธ์กฐ ๋ฌธ์„œ๋ฅผ ํ™•์ธํ•˜์„ธ์š”.

Cloud Storage์— ์ธ์ฆํ•˜๋ ค๋ฉด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ธฐ๋ณธ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ํด๋ผ์ด์–ธํŠธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์˜ ์ธ์ฆ ์„ค์ •์„ ์ฐธ์กฐํ•˜์„ธ์š”.

/**
 * TODO(developer): Uncomment the following lines before running the sample.
 */
// The ID of your GCS bucket
// const bucketName = 'your-unique-bucket-name';

// The ID of your GCS file
// const fileName = 'your-file-name';

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

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

// Optional:
// Set a generation-match precondition to avoid potential race conditions
// and data corruptions. The request to delete is aborted if the object's
// generation number does not match your precondition. For a destination
// object that does not yet exist, set the ifGenerationMatch precondition to 0
// If the destination object already exists in your bucket, set instead a
// generation-match precondition using its generation number.
const deleteOptions = {
  ifGenerationMatch: generationMatchPrecondition,
};
async function deleteFile() {
  await storage.bucket(bucketName).file(fileName).delete(deleteOptions);

  console.log(`gs://${bucketName}/${fileName} deleted`);
}

deleteFile().catch(console.error);

PHP

์ž์„ธํ•œ ๋‚ด์šฉ์€ Cloud Storage PHP API ์ฐธ์กฐ ๋ฌธ์„œ๋ฅผ ํ™•์ธํ•˜์„ธ์š”.

Cloud Storage์— ์ธ์ฆํ•˜๋ ค๋ฉด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ธฐ๋ณธ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ํด๋ผ์ด์–ธํŠธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์˜ ์ธ์ฆ ์„ค์ •์„ ์ฐธ์กฐํ•˜์„ธ์š”.

use Google\Cloud\Storage\StorageClient;

/**
 * Delete an object.
 *
 * @param string $bucketName The name of your Cloud Storage bucket.
 *        (e.g. 'my-bucket')
 * @param string $objectName The name of your Cloud Storage object.
 *        (e.g. 'my-object')
 */
function delete_object(string $bucketName, string $objectName): void
{
    $storage = new StorageClient();
    $bucket = $storage->bucket($bucketName);
    $object = $bucket->object($objectName);
    $object->delete();
    printf('Deleted gs://%s/%s' . PHP_EOL, $bucketName, $objectName);
}

Python

์ž์„ธํ•œ ๋‚ด์šฉ์€ Cloud Storage Python API ์ฐธ์กฐ ๋ฌธ์„œ๋ฅผ ํ™•์ธํ•˜์„ธ์š”.

Cloud Storage์— ์ธ์ฆํ•˜๋ ค๋ฉด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ธฐ๋ณธ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ํด๋ผ์ด์–ธํŠธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์˜ ์ธ์ฆ ์„ค์ •์„ ์ฐธ์กฐํ•˜์„ธ์š”.

from google.cloud import storage


def delete_blob(bucket_name, blob_name):
    """Deletes a blob from the bucket."""
    # bucket_name = "your-bucket-name"
    # blob_name = "your-object-name"

    storage_client = storage.Client()

    bucket = storage_client.bucket(bucket_name)
    blob = bucket.blob(blob_name)
    generation_match_precondition = None

    # Optional: set a generation-match precondition to avoid potential race conditions
    # and data corruptions. The request to delete is aborted if the object's
    # generation number does not match your precondition.
    blob.reload()  # Fetch blob metadata to use in generation_match_precondition.
    generation_match_precondition = blob.generation

    blob.delete(if_generation_match=generation_match_precondition)

    print(f"Blob {blob_name} deleted.")

Ruby

์ž์„ธํ•œ ๋‚ด์šฉ์€ Cloud Storage Ruby API ์ฐธ์กฐ ๋ฌธ์„œ๋ฅผ ํ™•์ธํ•˜์„ธ์š”.

Cloud Storage์— ์ธ์ฆํ•˜๋ ค๋ฉด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ธฐ๋ณธ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ํด๋ผ์ด์–ธํŠธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์˜ ์ธ์ฆ ์„ค์ •์„ ์ฐธ์กฐํ•˜์„ธ์š”.

def delete_file bucket_name:, file_name:
  # The ID of your GCS bucket
  # bucket_name = "your-unique-bucket-name"

  # The ID of your GCS object
  # file_name = "your-file-name"

  require "google/cloud/storage"

  storage = Google::Cloud::Storage.new
  bucket  = storage.bucket bucket_name, skip_lookup: true
  file    = bucket.file file_name

  file.delete

  puts "Deleted #{file.name}"
end

REST API

JSON API

  1. Authorization ํ—ค๋”์— ๋Œ€ํ•œ ์•ก์„ธ์Šค ํ† ํฐ์„ ์ƒ์„ฑํ•˜๋ ค๋ฉด gcloud CLI๊ฐ€ ์„ค์น˜ ๋ฐ ์ดˆ๊ธฐํ™”๋˜์–ด ์žˆ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

  2. cURL์„ ์‚ฌ์šฉํ•˜์—ฌ DELETE ์š”์ฒญ์œผ๋กœ JSON API๋ฅผ ํ˜ธ์ถœํ•ฉ๋‹ˆ๋‹ค.

    curl -X DELETE \
      -H "Authorization: Bearer $(gcloud auth print-access-token)" \
      "https://storage.googleapis.com/storage/v1/b/BUCKET_NAME/o/OBJECT_NAME"

    ๊ฐ ํ•ญ๋ชฉ์˜ ์˜๋ฏธ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

    • BUCKET_NAME์€ ์‚ญ์ œํ•  ๊ฐ์ฒด๊ฐ€ ํฌํ•จ๋œ ๋ฒ„ํ‚ท์˜ ์ด๋ฆ„์ž…๋‹ˆ๋‹ค. ์˜ˆ: my-bucket
    • OBJECT_NAME์€ ์‚ญ์ œํ•  ๊ฐ์ฒด์˜ URL ์ธ์ฝ”๋”ฉ ์ด๋ฆ„์ž…๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด pets/dog.png๋Š” pets%2Fdog.png๋กœ URL ์ธ์ฝ”๋”ฉ๋ฉ๋‹ˆ๋‹ค.

XML API

  1. Authorization ํ—ค๋”์— ๋Œ€ํ•œ ์•ก์„ธ์Šค ํ† ํฐ์„ ์ƒ์„ฑํ•˜๋ ค๋ฉด gcloud CLI๊ฐ€ ์„ค์น˜ ๋ฐ ์ดˆ๊ธฐํ™”๋˜์–ด ์žˆ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

  2. cURL์„ ์‚ฌ์šฉํ•˜์—ฌ DELETE Object ์š”์ฒญ์œผ๋กœ XML API๋ฅผ ํ˜ธ์ถœํ•ฉ๋‹ˆ๋‹ค.

    curl -X DELETE \
      -H "Authorization: Bearer $(gcloud auth print-access-token)" \
      "https://storage.googleapis.com/BUCKET_NAME/OBJECT_NAME"

    ๊ฐ ํ•ญ๋ชฉ์˜ ์˜๋ฏธ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

    • BUCKET_NAME์€ ์‚ญ์ œํ•  ๊ฐ์ฒด๊ฐ€ ํฌํ•จ๋œ ๋ฒ„ํ‚ท์˜ ์ด๋ฆ„์ž…๋‹ˆ๋‹ค. ์˜ˆ: my-bucket
    • OBJECT_NAME์€ ์‚ญ์ œํ•  ๊ฐ์ฒด์˜ URL ์ธ์ฝ”๋”ฉ ์ด๋ฆ„์ž…๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด pets/dog.png๋Š” pets%2Fdog.png๋กœ URL ์ธ์ฝ”๋”ฉ๋ฉ๋‹ˆ๋‹ค.

๊ฐ์ฒด ์ผ๊ด„ ์‚ญ์ œ

์ˆ˜์‹ญ๋งŒ ๊ฐœ ์ด์ƒ์˜ ๊ฐ์ฒด๋ฅผ ์ผ๊ด„ ์‚ญ์ œํ•˜๋ ค๋ฉด ํ”„๋กœ์„ธ์Šค ์™„๋ฃŒ์— ์‹œ๊ฐ„์ด ์˜ค๋ž˜ ๊ฑธ๋ฆฌ๋Š” gcloud storage์„ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค. ๋Œ€์‹  ๋‹ค์Œ ์˜ต์…˜ ์ค‘ ํ•˜๋‚˜๋ฅผ ๊ณ ๋ คํ•ด ๋ณด์„ธ์š”.

  • ๊ฐ์ฒด ์ˆ˜๋ช… ์ฃผ๊ธฐ ๊ด€๋ฆฌ ๊ธฐ๋Šฅ์€ ๊ฐ์ฒด ์ˆ˜๋ฅผ ์›ํ•˜๋Š” ๋งŒํผ ์‚ญ์ œํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ฒ„ํ‚ท์˜ ๊ฐ์ฒด๋ฅผ ์ผ๊ด„ ์‚ญ์ œํ•˜๋ ค๋ฉด ์กฐ๊ฑด์—์„œ Age๊ฐ€ 0์ผ๋กœ ์„ค์ •๋˜๊ณ  ์ž‘์—…์ด delete๋กœ ์„ค์ •๋œ ๋ฒ„ํ‚ท์—์„œ ์ˆ˜๋ช… ์ฃผ๊ธฐ ๊ตฌ์„ฑ ๊ทœ์น™์„ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์ด ๊ทœ์น™์„ ์„ค์ •ํ•˜๋ฉด Cloud Storage์—์„œ ์ผ๊ด„ ์‚ญ์ œ๋ฅผ ๋น„๋™๊ธฐ์ ์œผ๋กœ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

  • ๊ฐ์ฒด๋ฅผ ์ตœ๋Œ€ 100๋งŒ ๊ฐœ ์‚ญ์ œํ•˜๋Š” ๊ฒฝ์šฐ Google Cloud ์ฝ˜์†”๋„ ๊ถŒ์žฅ๋˜๋Š” ์˜ต์…˜์ž…๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ ์‚ญ์ œ ์š”์ฒญ์„ ์‹œ์ž‘ํ•˜๋ฉด ํ”„๋กœ์„ธ์Šค๊ฐ€ ๋ฐฑ๊ทธ๋ผ์šด๋“œ์—์„œ ์ˆ˜ํ–‰๋ฉ๋‹ˆ๋‹ค. Google Cloud ์ฝ˜์†” ํ—ค๋”์—์„œ ์•Œ๋ฆผ ๋ฒ„ํŠผ()์„ ํด๋ฆญํ•˜์—ฌ ์ผ๊ด„ ์‚ญ์ œ ์ƒํƒœ๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  • ํŠน์ • ํด๋ผ์ด์–ธํŠธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜๊ฑฐ๋‚˜ JSON API๋ฅผ ์ง์ ‘ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ ์‚ญ์ œ ์š”์ฒญ์„ ๋ฐฐ์น˜ํ•˜์—ฌ ํ•„์š”ํ•œ HTTP ์—ฐ๊ฒฐ ์ˆ˜๋ฅผ ์ค„์ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋‹ค์Œ ๋‹จ๊ณ„