This page shows you how to copy, rename, and move objects within and between buckets in Cloud Storage. For an overview of objects, read the Key Terms and see the Object naming requirements.
Copying an object
To copy an object in one of your Cloud Storage buckets:
Console
- Open the Cloud Storage browser in the Google Cloud Console.
Open the Cloud Storage browser In the list of buckets, click on the name of the bucket that contains the object you want to copy.
The Bucket details page opens, with the Objects tab selected.
Navigate to the object, which may be located in a folder.
Click the more actions menu (
) associated with the object.
Click Copy.
The Copy object pane appears.
In the Destination text box, type the name of the destination bucket and the name for the copied object.
You can alternatively click Browse to select your destination, but browse options are limited to buckets in the current project.
Click Copy.
See Troubleshooting for how to get detailed error information about failed operations in the Cloud Storage browser.
gsutil
Use the gsutil cp
command:
gsutil cp gs://SOURCE_BUCKET_NAME/SOURCE_OBJECT_NAME gs://DESTINATION_BUCKET_NAME/NAME_OF_COPY
Where:
SOURCE_BUCKET_NAME
is the name of the bucket containing the object you want to copy. For example,my-bucket
.SOURCE_OBJECT_NAME
is the name of the object you want to copy. For example,pets/dog.png
.DESTINATION_BUCKET_NAME
is the name of the bucket where you want to copy your object. For example,another-bucket
.NAME_OF_COPY
is the name you want to give the copy of your object. For example,shiba.png
.
If successful, the response looks like the following example:
Operation completed over 1 objects/58.8 KiB.
Code samples
For more information, see the
Cloud Storage C++ API reference documentation.
For more information, see the
Cloud Storage C# API reference documentation.
For more information, see the
Cloud Storage Go API reference documentation.
For more information, see the
Cloud Storage Java API reference documentation.
For more information, see the
Cloud Storage Node.js API reference documentation.
For more information, see the
Cloud Storage PHP API reference documentation.
For more information, see the
Cloud Storage Python API reference documentation.
For more information, see the
Cloud Storage Ruby API reference documentation.
C++
C#
Go
Java
Node.js
PHP
Python
Ruby
REST APIs
JSON API
- Get an authorization access token from the OAuth 2.0 Playground. Configure the playground to use your own OAuth credentials.
Use
cURL
to call the JSON API with aPOST
Object request:curl -X POST \ -H "Authorization: Bearer OAUTH2_TOKEN" \ -H "Content-Length: 0" \ "https://storage.googleapis.com/storage/v1/b/SOURCE_BUCKET_NAME/o/SOURCE_OBJECT_NAME/rewriteTo/b/DESTINATION_BUCKET_NAME/o/NAME_OF_COPY"
Where:
OAUTH2_TOKEN
is the name of the access token you generated in Step 1.SOURCE_BUCKET_NAME
is the name of the bucket containing the object you want to copy. For example,my-bucket
.SOURCE_OBJECT_NAME
is the name of the object you want to copy. For example,pets/dog.png
.DESTINATION_BUCKET_NAME
is the name of the bucket where you want to copy your object. For example,another-bucket
.NAME_OF_COPY
is the name you want to give the copy of your object. For example,shiba.png
.
Since the
rewrite
method copies data in limited-sized chunks, your copy might require multiple requests, especially for large objects.For example, the following response to a
rewrite
request indicates that you need to make additionalrewrite
requests:{ "kind": "storage#rewriteResponse", "totalBytesRewritten": 1048576, "objectSize": 10000000000, "done": false, "rewriteToken": TOKEN_VALUE }
Use the
rewriteToken
in a subsequent request to continue copying data:curl -X POST \ -H "Authorization: Bearer OAUTH2_TOKEN" \ -H "Content-Length: 0" \ -d '{"rewriteToken": "TOKEN_VALUE"}' \ "https://storage.googleapis.com/storage/v1/b/SOURCE_BUCKET_NAME/o/SOURCE_OBJECT_NAME/rewriteTo/b/DESTINATION_BUCKET_NAME/o/NAME_OF_COPY"
Where:
TOKEN_VALUE
is therewriteToken
value returned in the previous request.- All other values match those used in the previous request.
When the object is fully is copied, the last response has a
done
property set totrue
, there is norewriteToken
property, and the metadata of the copy is included in theresource
property.{ "kind": "storage#rewriteResponse", "totalBytesRewritten": 10000000000, "objectSize": 10000000000, "done": true, "resource": objects Resource }
XML API
- Get an authorization access token from the OAuth 2.0 Playground. Configure the playground to use your own OAuth credentials.
Use
cURL
to call the XML API with aPUT
Object request:curl -X PUT \ -H "Authorization: Bearer OAUTH2_TOKEN" \ -H "x-goog-copy-source: SOURCE_BUCKET_NAME/SOURCE_OBJECT_NAME" \ "https://storage.googleapis.com/DESTINATION_BUCKET_NAME/NAME_OF_COPY"
Where:
OAUTH2_TOKEN
is the name of the access token you generated in Step 1.SOURCE_BUCKET_NAME
is the name of the bucket containing the object you want to copy. For example,my-bucket
.SOURCE_OBJECT_NAME
is the name of the object you want to copy. For example,pets/dog.png
.DESTINATION_BUCKET_NAME
is the name of the bucket where you want to copy your object. For example,another-bucket
.NAME_OF_COPY
is the name you want to give the copy of your object. For example,shiba.png
.
Renaming an object
To rename an existing object in one of your Cloud Storage buckets:
Console
- Open the Cloud Storage browser in the Google Cloud Console.
Open the Cloud Storage browser In the list of buckets, click on the name of the bucket that contains the object you want to rename.
The Bucket details page opens, with the Objects tab selected.
Navigate to the object, which may be located in a folder.
Click the more actions menu (
) associated with the object.
Click Rename.
In the overlay window that appears, enter a new name for the object.
Click Rename.
See Troubleshooting for how to get detailed error information about failed operations in the Cloud Storage browser.
gsutil
Use the gsutil mv
command:
gsutil mv gs://BUCKET_NAME/OLD_OBJECT_NAME gs://BUCKET_NAME/NEW_OBJECT_NAME
Where:
BUCKET_NAME
is the name of the bucket containing the object you want to rename. For example,my-bucket
.OLD_OBJECT_NAME
is the name of the object you want to rename. For example,pets/dog.png
.NEW_OBJECT_NAME
is the new name you want to give your object. For example,pets/shiba.png
.
If successful, the response looks like the following example:
Operation completed over 1 objects/58.8 KiB.
Code samples
For more information, see the
Cloud Storage C++ API reference documentation.
For more information, see the
Cloud Storage C# API reference documentation.
For more information, see the
Cloud Storage Go API reference documentation.
For more information, see the
Cloud Storage Java API reference documentation.
For more information, see the
Cloud Storage Node.js API reference documentation.
For more information, see the
Cloud Storage PHP API reference documentation.
For more information, see the
Cloud Storage Python API reference documentation.
For more information, see the
Cloud Storage Ruby API reference documentation.
C++
C#
Go
Java
Node.js
PHP
Python
Ruby
REST APIs
JSON API
To rename an object using the JSON API directly, first make a copy of the object so that the copy has the desired new name and then delete the original object.
XML API
To rename an object using the XML API directly, first make a copy of the object so that the copy has the desired new name and then delete the original object.
Moving an object
To move an object in Cloud Storage:
Console
- Open the Cloud Storage browser in the Google Cloud Console.
Open the Cloud Storage browser In the list of buckets, click on the name of the bucket that contains the object you want to move.
The Bucket details page opens, with the Objects tab selected.
Navigate to the object, which may be located in a folder.
Click the more actions menu (
) associated with the object.
Click Move.
In the overlay window that appears, click Browse.
Select the destination for the object you are moving.
Click Select.
Click Move.
See Troubleshooting for how to get detailed error information about failed operations in the Cloud Storage browser.
gsutil
Use the gsutil mv
command:
gsutil mv gs://SOURCE_BUCKET_NAME/SOURCE_OBJECT_NAME gs://DESTINATION_BUCKET_NAME/DESTINATION_OBJECT_NAME
Where:
SOURCE_BUCKET_NAME
is the name of the bucket containing the object you want to move. For example,my-bucket
.SOURCE_OBJECT_NAME
is the name of the object you want to move. For example,pets/dog.png
.DESTINATION_BUCKET_NAME
is the name of the bucket where you want to move your object. For example,another-bucket
.DESTINATION_OBJECT_NAME
is the name you want to give your object in its new location. For example,shiba.png
.
If successful, the response looks like the following example:
Operation completed over 1 objects/58.8 KiB.
Code samples
For more information, see the
Cloud Storage C++ API reference documentation.
For more information, see the
Cloud Storage C# API reference documentation.
For more information, see the
Cloud Storage Go API reference documentation.
For more information, see the
Cloud Storage Java API reference documentation.
For more information, see the
Cloud Storage PHP API reference documentation.
For more information, see the
Cloud Storage Ruby API reference documentation.
C++
C#
Go
Java
PHP
Ruby
REST APIs
JSON API
To move an object using the JSON API directly, first make a copy of the object in the desired new location and then delete the original object.
XML API
To move an object using the XML API directly, first make a copy of the object in the desired new location and then delete the original object.
What's next
- Change the storage class of an object.
- Edit an object's metadata.
- Make objects and buckets publicly accessible.