Copies an object to a specified location. Optionally overrides metadata. Try it now or see an example .
If an
object
resource is not specified in the request body, then the metadata of the source object is used. If an object resource is specified in the request, it must include the
contentType
property.
The authenticated user must have
READER
permissions on the source
object
and
WRITER
permissions on the destination
bucket
.
Request
HTTP request
POST https://www.googleapis.com/storage/v1beta2/b/sourceBucket/o/sourceObject/copyTo/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.
|
sourceBucket
|
string
|
Name of the bucket in which to find the source object. |
sourceObject
|
string
|
Name of the source object. |
Optional query parameters | ||
ifGenerationMatch
|
unsigned long
|
Makes the operation conditional on whether the destination object's current generation matches the given value. |
ifGenerationNotMatch
|
unsigned long
|
Makes the operation conditional on whether the destination object's current generation does not match the given value. |
ifMetagenerationMatch
|
unsigned long
|
Makes the operation conditional on whether the destination object's current metageneration matches the given value. |
ifMetagenerationNotMatch
|
unsigned long
|
Makes the operation conditional on whether the destination object's current metageneration does not match the given value. |
ifSourceGenerationMatch
|
unsigned long
|
Makes the operation conditional on whether the source object's generation matches the given value. |
ifSourceGenerationNotMatch
|
unsigned long
|
Makes the operation conditional on whether the source object's generation does not match the given value. |
ifSourceMetagenerationMatch
|
unsigned long
|
Makes the operation conditional on whether the source object's current metageneration matches the given value. |
ifSourceMetagenerationNotMatch
|
unsigned 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:
|
sourceGeneration
|
unsigned 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 an object resource in the response body.
Examples
Note: The code examples available for this method do not represent all supported programming languages (see the client libraries page for a list of supported languages).
Python
Uses the Python client library .
# The destination object resource is entirely optional. If empty, we use # the source object's metadata. if reuse_metadata: destination_object_resource = {} else: destination_object_resource = { 'contentLanguage': 'en', 'metadata': {'my-key': 'my-value'}, } req = client.objects().copy( sourceBucket=bucket_name, sourceObject=old_object, destinationBucket=bucket_name, destinationObject=new_object, body=destination_object_resource) resp = req.execute() print json.dumps(resp, indent=2)
Try it!
Use the APIs Explorer below to call this method on live data and see the response. Alternatively, try the standalone Explorer .