Change object storage classes (original) (raw)

This page describes how to change the storage class of objects within a bucket through rewriting the object.

In order to get the required permissions for changing the storage class of an object through rewriting the object, ask your administrator to grant you the Storage Object User (roles/storage.objectUser) role on the bucket.

This role contains the permissions required to change the storage class of an object. To see the exact permissions that are required, expand theRequired permissions section:

Console

Individual object storage classes cannot be set through theGoogle Cloud console. Instead, use the Google Cloud CLI.

Command line

Use the gcloud storage objects update command with the--storage-class flag. For example:

gcloud storage objects update gs://BUCKET_NAME/OBJECT_NAME --storage-class=STORAGE_CLASS

Where:

Client libraries

C++

For more information, see theCloud Storage C++ API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

C#

For more information, see theCloud Storage C# API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

Go

For more information, see theCloud Storage Go API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

Java

For more information, see theCloud Storage Java API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

Node.js

For more information, see theCloud Storage Node.js API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

PHP

For more information, see theCloud Storage PHP API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

Python

For more information, see theCloud Storage Python API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

Ruby

For more information, see theCloud Storage Ruby API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

REST APIs

JSON API

  1. Have gcloud CLI installed and initialized, which lets you generate an access token for the Authorization header.
  2. Create a JSON file that contains the following information:
    {
    "storageClass": "STORAGE_CLASS"
    }
    Where:
    • STORAGE_CLASS is the newstorage class for your object. For example, nearline.
  3. Use cURL to call the JSON API with aPOST Object, request:
    curl -X POST --data-binary @JSON_FILE_NAME \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json" \
    "https://storage.googleapis.com/storage/v1/b/BUCKET_NAME/o/OBJECT_NAME/rewriteTo/b/BUCKET_NAME/o/OBJECT_NAME"
    Where:
    • JSON_FILE_NAME is the path for the JSON file that you created in Step 2.
    • BUCKET_NAME is the name of the bucket containing the original object. For example, my-bucket.
    • OBJECT_NAME is the URL-encoded name of the object. For example, pets/dog.png, URL-encoded aspets%2Fdog.png.

XML API

  1. Have gcloud CLI installed and initialized, which lets you generate an access token for the Authorization header.
  2. Use cURL to call the XML API with aPUT Object request:
    curl -X PUT --data-binary @OBJECT \
    -H "Authorization: Bearer $(gcloud auth print-access-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.
    • OBJECT_CONTENT_TYPE is thecontent type of the object. For example, image/png.
    • STORAGE_CLASS is the newstorage class for your object. For example, nearline.
    • BUCKET_NAME is the name of the bucket containing the object you are rewriting. For example,my-bucket.
    • OBJECT_NAME is the URL-encoded name of the object you are rewriting. For example, pets/dog.png, URL-encoded as pets%2Fdog.png.