Feature Overview
This API is used to copy the parts of an object from the source path to the destination path. You can use
x-cos-copy-source to specify the source object and use x-cos-copy-source-range to specify the byte range to copy (each part should be 1 MB to 5 GB).Note
The following two types of accounts can call this API:
Have the root account permissions.
Have the
GetObjecet API permission of the source object and the InitiateMultipartUpload, ListMultipartUploads, ListParts, PutObject, CompleteMultipartUpload, and AbortMultipartUpload API permissions under the destination path.Note
To call this API, you need to first call the Initiate Multipart Upload API to initialize the multipart upload and specify the destination path.
If the source and destination objects reside in two different regions and the part size is larger than 5 GB, use the multipart upload or multipart copy API to copy the object.
To upload an object in parts, you must first initialize the multipart upload. The response of the multipart upload initialization will include a unique descriptor
uploadId, which needs to be carried in the multipart upload request.
Versioning
If versioning is enabled for the bucket,
x-cos-copy-source identifies the current version of the object to copy. If the current version is a delete marker and no version is specified in x-cos-copy-source, COS will consider that the object has been deleted and return a 404 error. If you specify a versionId in x-cos-copy-source and the versionId is a delete marker, COS will return an HTTP 400 error as delete markers cannot be set in x-cos-copy-source.Requests
Sample Request
PUT /<ObjectKey>?partNumber=PartNumber&uploadId=UploadId HTTP/1.1Host: <Bucketname-APPID>.cos.<Region>.myqcloud.comDate: GMT DateAuthorization: Auth Stringx-cos-copy-source: <Bucketname>-<APPID>.cos.<Region>.myqcloud.com/filepathx-cos-copy-source-range: bytes=first-lastx-cos-copy-source-if-match: etagx-cos-copy-source-if-none-match : etagx-cos-copy-source-if-unmodified-since: time_stampx-cos-copy-source-if-modified-since: time_stamp
Note
Host: <BucketName-APPID>.cos.<Region>.myqcloud.com, where <BucketName-APPID> is the bucket name with the APPID suffix, such as examplebucket-1250000000. You can refer to the Bucket Overview > Basic Information and Bucket Overview > Bucket Naming Convention documentation. <Region> represents the available regions for COS, which can be found in the Regions and Access Domain Names documentation.
Authorization: Auth String (For more information, see Request Signature.)
Request Header
Common Header
Non-common Header
Required headers
This API uses the following required header:
Name | Description | Local Disk Types | Required |
x-cos-copy-source | URL of the source object. You can use versionid to specify the versionId of the object. | String | Required |
Recommended headers
This API uses the following recommended headers:
Name | Description | Local Disk Types | Required |
x-cos-copy-source-range | Byte range of the source object, specified in the format bytes=first-last, where first and last are zero-based offsets.For example, bytes=0-9 indicates that you want to copy the first 10 bytes of the source object. If not specified, the entire object will be copied. | String | Not required |
x-cos-copy-source-If-Modified-Since | Perform the operation if the Object has been modified after the specified time; otherwise, return a 412 status code. Can be used in conjunction with x-cos-copy-source-If-None-Match. When combined with other conditions, it may result in conflicts. | String | Not required |
x-cos-copy-source-If-Unmodified-Since | Perform the operation if the Object has not been modified after the specified time; otherwise, return a 412 status code. Can be used in conjunction with x-cos-copy-source-If-Match. When combined with other conditions, it may result in conflicts. | String | Not required |
x-cos-copy-source-If-Match | Perform the operation if the Object's Etag matches the given value; otherwise, return a 412 status code. Can be used in conjunction with x-cos-copy-source-If-Unmodified-Since. When combined with other conditions, it may result in conflicts. | String | Not required |
x-cos-copy-source-If-None-Match | Perform the operation if the Object's Etag does not match the given value; otherwise, return a 412 status code. Can be used in conjunction with x-cos-copy-source-If-Modified-Since. When combined with other conditions, it may result in conflicts. | String | Not required |
Request Parameters
Name | Description | Local Disk Types | Required |
partNumber | Part number | String | Required |
uploadId | To copy an object part, you must first initialize a multipart upload, after which a unique upload ID will be returned. This ID is required in the copy request. | String | Required |
Request Body
The request body of this request is empty.
Response
Response Header
Common Response Header
Special Response Header
Name | Description | Local Disk Types |
x-cos-copy-source-version-id | Version ID of the source object to copy (if versioning is enabled for the source bucket) | String |
x-cos-server-side-encryption | If the object is stored with COS-managed server-side encryption, the response will contain this header and the encryption algorithm used (AES256). | String |
Response Body
The return of this response body is application/xml data. Below is an example containing all the node data:
<?xml version="1.0" encoding="UTF-8" ?><CopyPartResult><ETag>"ba82b57cfdfda8bd17ad4e5879ebb4fe"</ETag><LastModified>2017-09-04T04:45:45</LastModified></CopyPartResult>
The nodes are described as follows:
Name | Description | Local Disk Types |
CopyPartResult | Results of the copy | String |
ETag | MD5 checksum of the object. ETag can be used to check whether the object content has changed. | String |
LastModified | Last modified time of the object, in GMT format | String |
Error Codes
Examples
Requests
PUT /exampleobject?partNumber=1&uploadId=1505706248ca8373f8a5cd52cb129f4bcf85e11dc8833df34f4f5bcc456c99c42cd1ffa2f9 HTTP/1.1User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.13.1.0 zlib/1.2.3 libidn/1.18 libssh2/1.2.2Accept: */*x-cos-copy-source:examplebucket-1250000000.cos.ap-shanghai.myqcloud.com/exampleobject1x-cos-copy-source-range: bytes=10-100Host: examplebucket-1250000000.cos.ap-shanghai.myqcloud.comAuthorization:q-sign-algorithm=sha1&q-ak=************************************&q-sign-time=1507530223;1508530223&q-key-time=1507530223;1508530223&q-header-list=&q-url-param-list=&q-signature=***********************************************
Response
HTTP/1.1 200 OKContent-Type: application/xmlContent-Length: 133Connection: keep-aliveDate: Mon, 04 Sep 2017 04:45:45 GMTServer: tencent-cosx-cos-request-id: NTlkYjFjYWJfMjQ4OGY3MGFfNGIz****<CopyPartResult><ETag>"ba82b57cfdfda8bd17ad4e5879ebb4fe"</ETag><LastModified>2017-09-04T04:45:45</LastModified></CopyPartResult>