Objects: copy

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

Generally, you should use the rewrite method instead of the copy method: the copy method uses the rewrite method, but calls it exactly once. Larger objects can require multiple rewrite calls, so copy attempts of such objects can lead to Deadline exceeded errors.

The authenticated user must have sufficient permission to use this method.

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

Request

HTTP request

POST https://storage.googleapis.com/storage/v1/b/sourceBucket/o/sourceObject/copyTo/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

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. For information about how to URL encode object names to be path safe, see Encoding URI path parts.
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.
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
destinationKmsKeyName string Resource name of the Cloud KMS key that will be used to encrypt the object. The Cloud KMS key must be located in same location as the object.

If the parameter is not specified, the method uses the destination bucket's default encryption key, if any, or the Google-managed encryption key.

If the object is large, re-encryption with the key may take too long and result in a Deadline exceeded error. For large objects, consider using the rewrite method instead.
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.
If iamConfiguration.uniformBucketLevelAccess.enabled is set to true, requests that include this parameter fail with a 400 Bad Request response.
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.
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.
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, optionally supply metadata to apply to the copied object using an object resource.

Response

If successful, this method returns an object resource in the response body.

Try it!

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