Swift copy an object

Copying an object allows you to make a server-side copy of an object, so that you do not have to download it and upload it under another container. To copy the contents of one object to another object, you can make either a PUT request or a COPY request with the API version, account, and the container name.

For a PUT request, use the destination container and object name in the request, and the source container and object in the request header.

For a Copy request, use the source container and object in the request, and the destination container and object in the request header. You must have write permission on the container to copy an object. The destination object name must be unique within the container. The request is not idempotent, so if you do not use a unique name, the request will update the destination object. You can use pseudo-hierarchical syntax in the object name to distinguish the destination object from the source object of the same name if it is under a different pseudo-hierarchical directory. You can include access control headers and metadata headers in the request.

Syntax

PUT /_AP_VERSION_/_ACCOUNT_/_TENANT_:_CONTAINER_ HTTP/1.1
X-Copy-From: _TENANT_:_SOURCE_CONTAINER_/_SOURCE_OBJECT_
Host: FULLY_QUALIFIED_DOMAIN_NAME
X-Auth-Token: _AUTH_TOKEN_

or alternatively:

Syntax

COPY /_AP_VERSION_/_ACCOUNT_/_TENANT_:_SOURCE_CONTAINER_/_SOURCE_OBJECT_ HTTP/1.1
Destination: _TENANT_:_DEST_CONTAINER_/_DEST_OBJECT_

Request Headers

X-Copy-From

Description

Used with a PUT request to define the source container/object path.

Type

String

Required

Yes, if using PUT.

Destination

Description

Used with a COPY request to define the destination container/object path.

Type

String

Required

Yes, if using COPY.

If-Modified-Since

Description

Only copies if modified since the date and time of the source object’s last_modified attribute.

Type

Date

Required

No

If-Unmodified-Since

Description

Only copies if not modified since the date and time of the source object’s last_modified attribute.

Type

Date

Required

No

Copy-If-Match

Description

Copies only if the ETag in the request matches the source object’s ETag.

Type

ETag

Required

No

Copy-If-None-Match

Description

Copies only if the ETag in the request does not match the source object’s ETag.

Type

ETag

Required

No