Rewrites a source object to a destination object. The source file is not modified, unless the source and destination objects are the same. Optionally overrides metadata.
For large objects, this method requires the use of multiple requests, which avoids having one
very long timeout for a single request. In such cases, the method responds with the done
flag set to false
and also returns a rewriteToken
. To
complete the rewrite, you must keep calling the endpoint using the rewriteToken
returned in the prior response until the done
flag is true
. 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
.
Keep the following in mind when using the rewrite method:
- A rewrite completes in a single request, and you do not need to make additional calls
specifying a
rewriteToken
if the following conditions are true:- The storage class of the object is not changing
- The source and destination are in the same location
- If the location is a dual-region, either the source bucket must have turbo replication enabled or the source object must have completed its replication across regions
- Rewriting an object is charged as a single Class A operation, even when it requires the usage
of a
rewriteToken
. However, depending on the storage classes and locations involved, a rewrite might incur other charges. For more information, see Cloud Storage pricing . - When you rewrite a composite object where the source and destination are different locations or storage classes, the result is a composite object that has a component count of 1.
- Any timeout logic that you set in conjunction with using this method should be at least 30 seconds.
Request
HTTP request
POST https://storage.googleapis.com/storage/v1/b/ sourceBucket /o/ sourceObject /rewriteTo/b/ destinationBucket /o/ destinationObject
In addition to standard query parameters , the following query parameters apply to this method.
To see an example of how to include query parameters in a request, see the JSON API Overview page.
Parameters
destinationBucket
string
bucket
value, if any.destinationObject
string
name
value, if any. For information about how
to URL encode object names to be path safe, see Encoding URI path parts
.sourceBucket
string
sourceObject
string
destinationKmsKeyName
string
If the parameter is not specified, the request uses the destination bucket's default encryption key, if any, or else it uses standard Cloud Storage encryption .
destinationPredefinedAcl
string
Acceptable values are:
-
authenticatedRead
: Object owner getsOWNER
access, andallAuthenticatedUsers
getREADER
access. -
bucketOwnerFullControl
: Object owner getsOWNER
access, and project team owners getOWNER
access. -
bucketOwnerRead
: Object owner getsOWNER
access, and project team owners getREADER
access. -
private
: Object owner getsOWNER
access. -
projectPrivate
: Object owner getsOWNER
access, and project team members get access according to their roles. -
publicRead
: Object owner getsOWNER
access, andallUsers
getREADER
access.
iamConfiguration.uniformBucketLevelAccess.enabled
is set to true
, requests that include this parameter fail with a 400 Bad Request
response.ifGenerationMatch
long
ifGenerationMatch
to 0 makes the
operation succeed only if there is no live destination object.ifGenerationNotMatch
long
ifGenerationNotMatch
to 0 makes the operation
succeed if there is a live version of the object.ifMetagenerationMatch
long
ifMetagenerationNotMatch
long
ifSourceGenerationMatch
long
ifSourceGenerationNotMatch
long
ifSourceMetagenerationMatch
long
ifSourceMetagenerationNotMatch
long
maxBytesRewrittenPerCall
long
rewriteToken
is invalid.projection
string
noAcl
, unless the object resource
specifies the acl
property, when it defaults to full
.Acceptable values are:
-
full
: Include all properties. -
noAcl
: Omit theowner
,acl
property.
rewriteToken
string
sourceGeneration
long
X-Goog-Copy-Source-Encryption-Algorithm
string
AES256
. Used if the source
object was encrypted with a customer-supplied
encryption key
.X-Goog-Copy-Source-Encryption-Key
string
X-Goog-Copy-Source-Encryption-Key-Sha256
string
X-Goog-Encryption-Algorithm
string
AES256
. Used for encrypting
the destination object with a customer-supplied encryption
key
.X-Goog-Encryption-Key
string
X-Goog-Encryption-Key-Sha256
string
Request body
In the request body, supply metadata to apply to the destination object by using an object resource
. If the request body
is empty, editable metadata
from the source object
is applied to the destination object, with the exception of any ACLs, object holds, or retention
configuration set on the source object. If you want to retain these from
the original object, they must be included in the request body.
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
1
|
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
1
|
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. |
For information about status and error codes returned by this API, see the reference page .
Try it!
Use the APIs Explorer below to call this method on live data and see the response.