Changing object storage classes

This page describes how to change the storage class of objects within a bucket through overwriting the object. To learn how to change object storage classes without overwriting an object, see the Object Lifecycle Management feature.

Console

Individual object storage classes cannot be set through the Console. Instead use gsutil.

gsutil

Use the -s flag in a rewrite command. For example:

gsutil rewrite -s [STORAGE_CLASS] gs://[PATH_TO_OBJECT]

Where:

  • [STORAGE_CLASS] is the new storage class for your object. For example, nearline.
  • [PATH_TO_OBJECT] is the name of the object whose class you want to change. For example, pets/dog.png.

REST APIs

JSON API

  1. Get an authorization access token from the OAuth 2.0 Playground. Configure the playground to use your own OAuth credentials.
  2. Create a .json file that contains the following information:

    {
      "storageClass": "[STORAGE_CLASS]"
    }

    Where:

    • [STORAGE_CLASS] is the new storage class for your object. For example, nearline.
  3. Use cURL to call the JSON API with a POST Object, request:

    curl -X POST --data-binary @[JSON_FILE_NAME].json \
      -H "Authorization: Bearer [OAUTH2_TOKEN]" \
      -H "Content-Type: application/json" \
      "https://www.googleapis.com/storage/v1/b/[BUCKET_NAME]/o/[OBJECT_NAME]/rewriteTo/b/[BUCKET_NAME]/o/[OBJECT_NAME]"

    Where:

    • [JSON_FILE_NAME] is the name of the JSON file you created in Step 2.
    • [OAUTH2_TOKEN] is the access token you generated in Step 1.
    • [BUCKET_NAME] is the name of the bucket containing the original object. For example, my-bucket.
    • [OBJECT_NAME] is the name of the object. For example, pets/dog.png.

XML API

  1. Get an authorization access token from the OAuth 2.0 Playground. Configure the playground to use your own OAuth credentials.
  2. Use cURL to call the XML API with a PUT Object request:

    curl -X PUT --data-binary @[OBJECT] \
      -H "Authorization: Bearer [OAUTH2_TOKEN]" \
      -H "Content-Type: [OBJECT_CONTENT_TYPE]" \
      -H "x-goog-storage-class: [STORAGE_CLASS]" \
      "https://storage.googleapis.com/[BUCKET_NAME]/[OBJECT_NAME]"

    Where:

    • [OBJECT] is the local path to the object whose storage class you want to change (you must re-upload the object when changing storage class with the XML API). For example, Desktop/dog.png.
    • [OAUTH2_TOKEN] is the access token you generated in Step 1.
    • [OBJECT_CONTENT_TYPE] is the content type of the object. For example, image/png.
    • [STORAGE_CLASS] is the new storage class for your object. For example, nearline.
    • [BUCKET_NAME] is the name of the bucket containing the object you are overwriting. For example, my-bucket.
    • [OBJECT_NAME] is the name of the object you are overwriting. For example, pets/dog.png.
Bu sayfayı yararlı buldunuz mu? Lütfen görüşünüzü bildirin:

Şunun hakkında geri bildirim gönderin...

Yardım mı gerekiyor? Destek sayfamızı ziyaret edin.