All Products
Search
Document Center

Object Storage Service:CopyObject

Last Updated:Apr 01, 2026

Use the CopyObject operation to copy an object between the same or different buckets within the same region.

Versioning

By default, x-oss-copy-source copies the current version of an object. To copy a specific version, include the version ID in x-oss-copy-source. If the specified source version is a delete marker, OSS returns a 404 error, indicating the object does not exist.

To restore a previous version of an object, copy that version to the same bucket. This action makes the copied version the new current version.

If versioning is enabled for the destination bucket, OSS automatically generates a unique version ID for the newly copied object. This version ID is returned in the x-oss-version-id response header. If versioning is disabled or suspended for the destination bucket, OSS generates a version with a null version ID for the new object. This new version overwrites any existing version that has a null version ID.

Limitations

  • Object size limits

    • Objects larger than 5 GB can be copied within the same bucket if you do not change the encryption method or storage class.

    • If the source and destination buckets are different, and you do not change the encryption method or storage class of the object during the copy operation, the object cannot be larger than 5 GB.

    • If you change the object's encryption method or storage class during the copy, the object size is limited to 1 GB. For larger objects, you must use the UploadPartCopy operation.

  • Permission

    Both the CopyObject and UploadPartCopy operations require read permission on the source object.

  • If you use the CopyObject operation in a bucket where versioning is disabled and the source and destination objects are the same:

    • If the encryption method or storage class is not changed, OSS modifies only the metadata of the object and does not copy its content.

    • If the encryption method or storage class is changed, OSS modifies the metadata and also copies the content of the object.

  • Source object is a symbolic link

    If you use the CopyObject operation on a symbolic link, only the symbolic link is copied. The content of the object to which the symbolic link points is not copied.

  • Hierarchical namespace is enabled for the bucket

    You cannot copy directories within a bucket for which hierarchical namespace is enabled.

  • Preventing object overwrite conflicts

    If you enable Prevent File Overwrite, you cannot use CopyObject to change an object's storage class, such as from Standard to Archive Storage. Instead, use a lifecycle rule to automatically transition the storage class.

  • ObjectWorm limitations

    When you copy an appendable object, you cannot include ObjectWorm-related parameters in the request.

Permissions

By default, an Alibaba Cloud account has full permissions. RAM users or RAM roles under an Alibaba Cloud account do not have any permissions by default. The Alibaba Cloud account or account administrator must grant operation permissions through RAM policies or Bucket Policy.

API

Action

Description

CopyObject

oss:GetObject

Copies objects within a bucket or between buckets in the same region.

oss:PutObject

oss:GetObjectVersion

If you specify the source object version through versionId, this permission is also required.

oss:GetObjectTagging

If you copy object tags through x-oss-tagging, these permissions are required.

oss:PutObjectTagging

oss:GetObjectVersionTagging

If you specify the tags of a specific version of the source object through versionId, this permission is also required.

kms:GenerateDataKey

When copying an object, if the destination object metadata contains X-Oss-Server-Side-Encryption: KMS, these two permissions are required.

kms:Decrypt

Note

If ObjectWorm is enabled for the destination bucket, the copied object inherits the bucket's default retention policy. You can specify a separate retention policy for the destination object by using the x-oss-object-worm-mode and x-oss-object-worm-retain-until-date request headers. The retention policy of the source object is not copied to the destination object.

Billing

  • Each call to the CopyObject operation counts as one PUT request for the destination bucket.

  • The CopyObject operation increases the storage usage of the destination bucket.

  • Using CopyObject to change an object's storage class is a data overwrite operation. For example, if an Infrequent Access (IA) object is overwritten and its storage class is changed to Standard within 10 days of its creation, a fee is charged for 20 days of IA storage because the minimum storage duration was not met. For more information about storage fees, see Storage fees.

  • Calling the CopyObject operation on an Infrequent Access (IA) object incurs a data retrieval fee for IA storage. If the source object is an unrestored Archive Storage object in a bucket with real-time access enabled, a data retrieval fee for real-time access is incurred. These fees are charged to the account that owns the source bucket. For more information about billing, see Data processing fees.

Request syntax

PUT /DestObjectName HTTP/1.1
Host: DestBucketName.oss-cn-hangzhou.aliyuncs.com
Date: GMT Date
Authorization: SignatureValue
x-oss-copy-source: /SourceBucketName/SourceObjectName

Request headers

All request headers for a copy operation start with x-oss- and must be included in the signature string.

Parameter

Type

Required

Value

Description

x-oss-forbid-overwrite

String

No

true

Specifies whether to overwrite a destination object that has the same name. If versioning is enabled or suspended for the destination bucket, the x-oss-forbid-overwrite request header is ignored and the object is allowed to be overwritten.

  • If x-oss-forbid-overwrite is not specified or x-oss-forbid-overwrite is set to false, overwriting a destination Object with the same name is allowed.

  • If you set x-oss-forbid-overwrite to true, an existing destination object with the same name is not overwritten.

Setting the x-oss-forbid-overwrite request header degrades QPS performance. If you need to perform a large number of operations that use the x-x-oss-forbid-overwrite request header (QPS>1000), contact technical support to avoid disruptions to your business.

Default value: false

x-oss-copy-source

String

Yes

/oss-example/oss.jpg

Specifies the source path for the copy operation.

Default value: None

x-oss-copy-source-if-match

String

No

5B3C1A2E053D763E1B002CC607C5****

The operation proceeds only if the source object's ETag matches the specified ETag.

Default value: None

x-oss-copy-source-if-none-match

String

No

5B3C1A2E053D763E1B002CC607C5****

The operation proceeds only if the source object's ETag does not match the specified ETag.

Default value: None

x-oss-copy-source-if-unmodified-since

String

No

Mon, 11 May 2020 08:16:23 GMT

Copies the object only if it has not been modified since the specified time.

Default value: None

x-oss-copy-source-if-modified-since

String

No

Mon, 11 May 2020 08:16:23 GMT

Copies the object only if it has been modified since the specified time.

Default value: None

x-oss-metadata-directive

String

No

COPY

Specifies whether to copy the source object's metadata or replace it.

  • COPY (default): Copies the metadata from the source object to the destination object.

    OSS does not copy the x-oss-server-side-encryption setting from the source object to the destination object. The server-side encryption of the destination object depends on whether x-oss-server-side-encryption is specified in the copy operation.

  • REPLACE: Ignores the metadata of the source object and uses the metadata specified in the request.

Important

If the source and destination objects are the same and versioning is not enabled, the metadata of the source object is ignored regardless of the value of x-oss-metadata-directive. The destination object uses the metadata specified in the request.

x-oss-server-side-encryption

String

No

AES256

Specifies the server-side encryption algorithm that OSS uses when it creates the destination object.

Valid values: AES256 and KMS

Important

You cannot specify x-oss-server-side-encryption when you copy a symbolic link object.

You can use the KMS encryption algorithm only after you purchase a KMS suite. Otherwise, OSS returns the KmsServiceNotEnabled error.

  • If you do not specify x-oss-server-side-encryption in the copy operation, the destination object is not server-side encrypted, regardless of whether the source object was encrypted.

  • If you specify x-oss-server-side-encryption in the copy operation, the destination object is server-side encrypted, regardless of whether the source object was encrypted. The response header for the copy operation includes x-oss-server-side-encryption and its value is the encryption algorithm of the destination object.

    When the destination object is downloaded, the response header also includes x-oss-server-side-encryption and its value is the encryption algorithm of the object.

x-oss-server-side-encryption-key-id

String

No

9468da86-3509-4f8d-a61e-6eab1eac****

Specifies the ID of the customer master key (CMK) that is managed by KMS.

This parameter is valid only when x-oss-server-side-encryption is set to KMS.

x-oss-object-acl

String

No

private

Specifies the access control list (ACL) for the destination object when it is created.

Valid values:

  • default (default): The object inherits the ACL of the bucket.

  • private: The object is a private resource. Only the object owner and authorized users have read and write permissions on the object. Other users cannot access the object.

  • public-read: The object is a public-read resource. Only the object owner and authorized users have read and write permissions on the object. Other users have only read permissions. Use this permission with caution.

  • public-read-write: The object is a public read and write resource. All users have read and write permissions on the object. Use this permission with caution.

For more information about access permissions, see Object ACL.

x-oss-storage-class

String

No

Standard

Specifies the storage class of the object.

For a bucket of any storage class, if you specify this header when you upload an object, the uploaded object is stored in the specified storage class. For example, if you set x-oss-storage-class to Standard when you upload an object to an IA bucket, the object is stored as a Standard object.

Valid values:

  • Standard (default): Standard storage

  • IA: Infrequent Access (IA)

  • Archive: Archive Storage

  • ColdArchive: Cold Archive

  • DeepColdArchive: Deep Cold Archive

    Important

    If you need to copy a large number of objects, directly setting their storage class to Deep Cold Archive will result in high PUT request fees. We recommend that you use lifecycle rules to transition the objects to the Deep Cold Archive storage class to reduce PUT request fees.

For more information about storage classes, see Storage classes.

x-oss-tagging

String

No

a:1

Specifies tags for the object. To specify multiple tags, use an ampersand (&) as a separator, for example: TagA=A&TagB=B.

Note

The key and value must be URL-encoded. If a tag does not contain an equal sign (=), its value is considered an empty string.

x-oss-tagging-directive

String

No

Copy

Specifies how to set the tags of the destination object.

  • Copy (default): Copies the tags from the source object to the destination object.

  • Replace: Ignores the tags of the source object and uses the tags specified in the request.

x-oss-object-worm-mode

String

No

COMPLIANCE

Specifies the retention policy mode for the destination object. Valid value: COMPLIANCE. This header is valid only if ObjectWorm is enabled for the destination bucket.

x-oss-object-worm-retain-until-date

String

No

2025-01-01T00:00:00.000Z

Specifies the retention expiration date for the destination object. The date must be in ISO 8601 format. This header is valid only if ObjectWorm is enabled for the destination bucket.

This operation also uses common request headers, such as Host and Date. For more information, see Common Request Headers.

Response headers

This operation uses only common response headers. For more information, see Common Response Headers.

Response elements

Parameter

Type

Example

Description

CopyObjectResult

Container

N/A

A container for the results of the CopyObject operation.

Default value: None

ETag

String

5B3C1A2E053D763E1B002CC607C5****

The ETag of the destination object.

Parent element: CopyObjectResult

LastModified

String

Fri, 24 Feb 2012 07:18:48 GMT

The time when the destination object was last updated.

Parent element: CopyObjectResult

Examples

  • Versioning is disabled

    Sample request

    PUT /test%2FAK.txt HTTP/1.1
    Host: tesx.oss-cn-zhangjiakou.aliyuncs.com
    Accept-Encoding: identity
    User-Agent: aliyun-sdk-python/2.6.0(Windows/7/AMD64;3.7.0)
    Accept: text/html
    Connection: keep-alive
    x-oss-copy-source: /test/AK.txt
    date: Fri, 28 Dec 2018 09:41:55 GMT
    authorization: OSS4-HMAC-SHA256 Credential=LTAI********************/20250417/cn-hangzhou/oss/aliyun_v4_request,AdditionalHeaders=content-length,Signature=a7c3554c729d71929e0b84489addee6b2e8d5cb48595adfc51868c299c0c218e
    Content-Length: 0

    Sample response

    The x-oss-hash-crc64ecma header indicates the 64-bit CRC value of the object. This value is calculated based on the CRC-64/XZ standard. The CopyObject operation does not guarantee that the generated object has a 64-bit CRC value.

    HTTP/1.1 200 OK
    Server: AliyunOSS
    Date: Fri, 28 Dec 2018 09:41:56 GMT
    Content-Type: application/xml
    Content-Length: 184
    Connection: keep-alive
    x-oss-request-id: 5C25EFE4462CE00EC6D87156
    ETag: "F2064A169EE92E9775EE5324D0B1****"
    x-oss-hash-crc64ecma: 12753002859196105360
    x-oss-server-time: 150
    <?xml version="1.0" encoding="UTF-8"?>
    <CopyObjectResult>
      <ETag>"F2064A169EE92E9775EE5324D0B1****"</ETag>
      <LastModified>2018-12-28T09:41:56.000Z</LastModified>
    </CopyObjectResult>
  • Copy an object without specifying a version ID

    Sample request

    PUT /dest-object-example HTTP/1.1
    Host: versioning-copy.oss-cn-hangzhou.aliyuncs.com
    Date: Tue, 09 Apr 2019 03:45:32 GMT
    Authorization: OSS4-HMAC-SHA256 Credential=LTAI********************/20250417/cn-hangzhou/oss/aliyun_v4_request,Signature=a7c3554c729d71929e0b84489addee6b2e8d5cb48595adfc51868c299c0c218e
    x-oss-copy-source: /versioning-copy-source/source-object

    Sample response

    In this example, x-oss-copy-source-version-id is the version ID of the source object, which is the current version. The x-oss-version-id header contains the version ID of the newly copied object.

    HTTP/1.1 200 OK
    x-oss-copy-source-version-id: CAEQNRiBgIC28uaA0BYiIDY5OGIwNmNlNjYyMTRjNTc4N2M2OGNiMjZkZTQ2****
    x-oss-version-id: CAEQNxiBgIDG8uaA0BYiIGZhZDRkZTk5Zjg3YzRhNzdiMWEwZGViNDM1NTFh****
    x-oss-request-id: 5CAC155CB7AEADE01700****
    Content-Type: application/xml
    Content-Length: 184
    Connection: keep-alive
    Date: Tue, 09 Apr 2019 03:45:32 GMT
    Server: AliyunOSS
    <?xml version="1.0" encoding="UTF-8"?>
    <CopyObjectResult>
      <ETag>"C81E728D9D4C2F636F067F89CC14****"</ETag>
      <LastModified>2019-04-09T03:45:32.000Z</LastModified>
    </CopyObjectResult>
  • Copy an object by specifying a version ID

    Sample request

    PUT /dest-object-example HTTP/1.1
    Host: versioning-copy.oss-cn-hangzhou.aliyuncs.com
    Date: Tue, 09 Apr 2019 03:45:32 GMT
    Authorization: OSS4-HMAC-SHA256 Credential=LTAI********************/20250417/cn-hangzhou/oss/aliyun_v4_request,Signature=a7c3554c729d71929e0b84489addee6b2e8d5cb48595adfc51868c299c0c218e
    x-oss-copy-source: /versioning-copy-source/source-object?versionId=CAEQNRiBgICv8uaA0BYiIDliZDc3MTc1NjE5MjRkMDI4ZGU4MTZkYjY1ZDgy****

    Sample response

    In this example, x-oss-copy-source-version-id is the version ID of the source object, which is the version specified in the x-oss-copy-source request header. The x-oss-version-id header contains the version ID of the newly copied object.

    HTTP/1.1 200 OK
    x-oss-copy-source-version-id: CAEQNRiBgICv8uaA0BYiIDliZDc3MTc1NjE5MjRkMDI4ZGU4MTZkYjY1ZDgy****
    x-oss-version-id: CAEQNxiBgMDP8uaA0BYiIDIyNGNhZDQ1M2M3NzRkZThiNzE0N2I3ZDkxOWY4****
    x-oss-request-id: 5CAC155CB7AEADE01700****
    Content-Type: application/xml
    Content-Length: 184
    Connection: keep-alive
    Date: Tue, 09 Apr 2019 03:45:32 GMT
    Server: AliyunOSS
    <?xml version="1.0" encoding="UTF-8"?>
    <CopyObjectResult>
      <ETag>"C4CA4238A0B923820DCC509A6F75****"</ETag>
      <LastModified>2019-04-09T03:45:32.000Z</LastModified>
    </CopyObjectResult>

SDKs

You can use the SDKs for the following languages to call this operation:

ossutil CLI

For the ossutil command that corresponds to the CopyObject operation, see copy-object.

Error codes

Error code

HTTP status code

Description

InvalidArgument

400

The value of a parameter, such as x-oss-storage-class, is invalid.

PreconditionFailed

412

This error is returned for one of the following reasons:

  • The x-oss-copy-source-if-match request header is specified, but the ETag of the source object does not match the specified ETag.

  • The x-oss-copy-source-if-unmodified-since request header is specified, but the source object was modified after the specified time.

NotModified

304

This error is returned for one of the following reasons:

  • The x-oss-copy-source-if-none-match request header is specified, but the ETag of the source object matches the specified ETag.

  • The x-oss-copy-source-if-modified-since request header is specified, but the source object has not been modified since the specified time.

KmsServiceNotEnabled

403

You set x-oss-server-side-encryption to KMS, but you have not purchased a KMS suite.

FileAlreadyExists

409

This error is returned for one of the following reasons:

  • The request header includes x-oss-forbid-overwrite=true to prevent an object with the same name from being overwritten, but an object with that name already exists in the bucket.

  • The hierarchical namespace feature is enabled for the bucket, and you try to copy an object where the source or destination object is a directory.

FileImmutable

409

This error is returned when you attempt to modify an object that is protected by an ObjectWorm retention policy.

FAQ

Does CopyObject support copying multiple objects at once?

The CopyObject operation copies only a single object. To copy multiple objects in a batch, use the ossutil command-line tool.