This page describes how to change the storage class of objects within a bucket through rewriting the object.
- To learn how to change object storage classes without rewriting an object, see the Object Lifecycle Management feature.
- To learn how Cloud Storage can automatically manage your object's storage classes, see the Autoclass feature.
Required roles
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 the Required permissions section:
Required permissions
storage.objects.create
storage.objects.delete
storage.objects.get
storage.objects.list
You might also be able to get these permissions with other predefined roles or custom roles.
For instructions on granting roles on buckets, see Use IAM with buckets.
Change an object's storage class
Complete the following steps to change an object's storage class:
Console
Individual object storage classes cannot be set through the Google 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:
BUCKET_NAME
is the name of the bucket containing the object whose class you want to change. For example,my-bucket
.OBJECT_NAME
is the name of the object whose class you want to change. For example,pets/dog.png
.STORAGE_CLASS
is the new storage class for your object. For example,nearline
.
Client libraries
For more information, see the
Cloud Storage C++ API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage C# API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage Go API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage Java API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage Node.js API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage PHP API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage Python API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage Ruby API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
C++
C#
Go
Java
Node.js
PHP
Python
Ruby
REST APIs
JSON API
Have gcloud CLI installed and initialized, which lets you generate an access token for the
Authorization
header.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
.
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
Have gcloud CLI installed and initialized, which lets you generate an access token for the
Authorization
header.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 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 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 aspets%2Fdog.png
.
What's next
- Learn about available storage classes.
- Change object storage classes with Object Lifecycle Management.
- Explore other Cloud Storage data lifecycle features.
- Learn about object metadata.
- Learn how to use request preconditions to prevent race conditions.