Objects: rewrite

Rewrites a source object to a destination object. Optionally overrides metadata. Try it now.

The authenticated user must have READER permissions on the source object and WRITER permissions on the destination bucket.

This method copies data using multiple requests so large objects can be copied with a normal length timeout per request rather than one very long timeout for a single request.

Keep the following in mind when using the rewrite method:

  • If the source and destination are the same location and storage class and use the same server-side encryption (either the default server-side encryption, or the same customer-supplied encryption key), the rewrite method returns in a single RPC, that is, you do not need to use additional calls specifying a rewriteToken.There are no additional I/O charges. If the source and destination are different locations or storage classes, or if they are encrypted differently, the rewrite method might require multiple calls and there will be I/O charges (see pricing).
  • When you rewrite a composite object where the source and destination are different locations and/or storage classes, the result will be a composite object containing a single component (and, as always with composite objects, it will have only a crc32c checksum, not an MD5).
  • You must complete rewrite operations within 1 week of when the rewriteToken was created. Attempts to use the token after it has expired fail with a 410 error.

To rewrite objects encrypted by a customer-supplied encryption key, use the headers listed on the Encryption page in your request.

Request

HTTP request

POST https://www.googleapis.com/storage/v1/b/sourceBucket/o/sourceObject/rewriteTo/b/destinationBucket/o/destinationObject

Parameters

Parameter name Value Description
Path parameters
destinationBucket string Name of the bucket in which to store the new object. Overrides the provided object metadata's bucket value, if any.
destinationObject string Name of the new object. Required when the object metadata is not otherwise provided. Overrides the object metadata's name value, if any. For information about how to URL encode object names to be path safe, see Encoding URI Path Parts.
sourceBucket string Name of the bucket in which to find the source object.
sourceObject string Name of the source object. For information about how to URL encode object names to be path safe, see Encoding URI Path Parts.
Optional query parameters
destinationPredefinedAcl string Apply a predefined set of access controls to the destination object.

Acceptable values are:
  • "authenticatedRead": Object owner gets OWNER access, and allAuthenticatedUsers get READER access.
  • "bucketOwnerFullControl": Object owner gets OWNER access, and project team owners get OWNER access.
  • "bucketOwnerRead": Object owner gets OWNER access, and project team owners get READER access.
  • "private": Object owner gets OWNER access.
  • "projectPrivate": Object owner gets OWNER access, and project team members get access according to their roles.
  • "publicRead": Object owner gets OWNER access, and allUsers get READER access.
ifGenerationMatch long Makes the operation conditional on whether the destination object's current generation matches the given value. Setting to 0 makes the operation succeed only if there are no live versions of the object.
ifGenerationNotMatch long Makes the operation conditional on whether the destination object's current generation does not match the given value. If no live object exists, the precondition fails. Setting to 0 makes the operation succeed only if there is a live version of the object.
ifMetagenerationMatch long Makes the operation conditional on whether the destination object's current metageneration matches the given value.
ifMetagenerationNotMatch long Makes the operation conditional on whether the destination object's current metageneration does not match the given value.
ifSourceGenerationMatch long Makes the operation conditional on whether the source object's generation matches the given value.
ifSourceGenerationNotMatch long Makes the operation conditional on whether the source object's generation does not match the given value.
ifSourceMetagenerationMatch long Makes the operation conditional on whether the source object's current metageneration matches the given value.
ifSourceMetagenerationNotMatch long Makes the operation conditional on whether the source object's current metageneration does not match the given value.
maxBytesRewrittenPerCall long The maximum number of bytes that will be rewritten per rewrite request. Most callers shouldn't need to specify this parameter - it is primarily in place to support testing. If specified the value must be an integral multiple of 1 MiB (1048576). Also, this only applies to requests where the source and destination span locations and/or storage classes. Finally, this value must not change across rewrite calls else you'll get an error that the rewriteToken is invalid.
projection string Set of properties to return. Defaults to noAcl, unless the object resource specifies the acl property, when it defaults to full.

Acceptable values are:
  • "full": Include all properties.
  • "noAcl": Omit the owner, acl property.
rewriteToken string Include this field (from the previous rewrite response) on each rewrite request after the first one, until the rewrite response 'done' flag is true. Calls that provide a rewriteToken can omit all other request fields, but if included those fields must match the values provided in the first rewrite request.
sourceGeneration long If present, selects a specific revision of the source object (as opposed to the latest version, the default).

Request body

In the request body, supply an object resource.

Response

If successful, this method returns a response body with the following structure:

{
  "kind": "storage#rewriteResponse",
  "totalBytesRewritten": unsigned long,
  "objectSize": unsigned long,
  "done": boolean,
  "rewriteToken": string,
  "resource": objects Resource
}
Property name Value Description Notes
kind string The kind of item this is.
totalBytesRewritten unsigned long The total bytes written so far, which can be used to provide a waiting user with a progress indicator. This property is always present in the response.
objectSize unsigned long The total size of the object being copied in bytes. This property is always present in the response.
done boolean true if the copy is finished; otherwise, false if the copy is in progress. This property is always present in the response.
rewriteToken string A token to use in subsequent requests to continue copying data. This token is present in the response only when there is more data to copy.
resource nested object A resource containing the metadata for the copied-to object. This property is present in the response only when copying completes.

Try it!

Use the APIs Explorer below to call this method on live data and see the response.

Monitor your resources on the go

Get the Google Cloud Console app to help you manage your projects.

Send feedback about...

Cloud Storage Documentation