tencent cloud

Cloud Object Storage

Copy Object Recursive

Download
Mode fokus
Ukuran font
Terakhir diperbarui: 2026-08-25 15:01:06
Diterjemahkan oleh AI

Overview

Recursively copy the entire directory tree, including all subfiles and subdirectories, to the target location.
Attention:
Errors may be returned when a COS Agent Bucket receives a copy request or is in the process of copying an object. If an error occurs before the copy operation starts, you receive a standard error response. If an error occurs during the copy operation, the system still returns HTTP 200 OK and includes the error in the response body. This means an HTTP 200 OK response can indicate either success or failure. When using this API, you must further determine the success or failure of the copy request based on the response body content and handle the result accordingly.

Request

Request Syntax

PUT /<ObjectKey>?recursive HTTP/1.1
Host: <BucketName-APPID>.cos.<Region>.myqcloud.com
x-cos-copy-source: <BucketName-APPID>.cos.<Region>.myqcloud.com/<SourceObjectKey>
Authorization: Auth String

Note:
Host: <BucketName-APPID>.cos.<Region>.myqcloud.com. Here, <BucketName-APPID> is the bucket name with the APPID suffix, for example, smhxxxxxxxxxxxxx-1250000000. <Region> is the available region. For details, see Product Overview.
ObjectKey: The path to the target object.
SourceObjectKey: The path to the object to be copied.
Authorization: Auth String (For details, see Request Signature).

Request Parameters

Term
Description
Type
Required
recursive
Enables recursive directory copy mode. No value assignment is required; it only needs to appear in the URL.
No value
Yes
conflict_resolution_strategy
Conflict resolution policy. For recursive directory copy, the optional values are ask and rename, with ask as the default.
In case of a conflict, the system returns HTTP 409 Conflict and the SameNameDirectoryOrFileExists error code.
rename: Automatically renames the last-level directory in case of a conflict.
string
No

Request Body

This API has no request body.

Response

Response Headers

This API only returns common response headers. For details, see Common Response Headers.

Response Body

The request is successful, returning application/xml data.
<CopyObjectResult>
<ETag>&#34;etag-value&#34;</ETag>
<LastModified>2025-01-15T10:30:00Z</LastModified>
<CRC64>xxx</CRC64>
</CopyObjectResult>
The detailed node descriptions are as follows:
Node Name (Keyword)
Parent Node
Description
Type
CopyObjectResult
None
All information for the Copy Object Recursive result.
Container
CopyObjectResult content of Container nodes:
Node Name (Keyword)
Parent Node
Description
Type
ETag
CopyObjectResult
The ETag value of the target object (enclosed in double quotes).
string
LastModified
CopyObjectResult
The last modification time of the target object, in RFC 3339 format.
date
CRC64
CopyObjectResult
The CRC64 value of the target object.
integer

Examples

Example One: Simple Case

Request

PUT /myspace/bbb?recursive HTTP/1.1
Host: smhxxx-1250000000.cos.ap-chengdu.myqcloud.com
x-cos-copy-source: smhxxx-1250000000.cos.ap-chengdu.myqcloud.com/myspace/aaa
Authorization: q-sign-algorithm=sha1&q-ak=************************************&q-sign-time=1566302375;1566309575&q-key-time=1566302375;1566309575&q-header-list=content-length;content-md5;content-type;date;host&q-url-param-list=delete&q-signature=****************************************


Response

HTTP/1.1 200 OK
Content-Type: application/xml
Transfer-Encoding: chunked
Connection: keep-alive
Date: Tue, 20 Aug 2019 11:59:35 GMT
x-cos-request-id: NWQ1YmUwYTdfM2FiMDJhMDlfYzczN18zMGM1****

<CopyObjectResult>
<ETag>&#34;d-1780579801973809791&#34;</ETag>
<LastModified>2026-06-04T13:30:01Z</LastModified>
<CRC64>5404623458528365127</CRC64>
</CopyObjectResult>

Example Two: Destination Already Exists During Recursive Copy

Request

PUT /myspace/bbb?recursive HTTP/1.1
Host: smhxxx-1250000000.cos.ap-chengdu.myqcloud.com
x-cos-copy-source: smhxxx-1250000000.cos.ap-chengdu.myqcloud.com/myspace/aaa
Authorization: q-sign-algorithm=sha1&q-ak=************************************&q-sign-time=1566302375;1566309575&q-key-time=1566302375;1566309575&q-header-list=content-length;content-md5;content-type;date;host&q-url-param-list=delete&q-signature=****************************************


Response

HTTP/1.1 200 OK
Content-Type: application/xml
Transfer-Encoding: chunked
Connection: keep-alive
Date: Tue, 20 Aug 2019 11:59:35 GMT
x-cos-request-id: NWQ1YmUwYTdfM2FiMDJhMDlfYzczN18zMGM1****

<Error>
<Code>FileAlreadyExists</Code>
<Message>The destination directory already exists. Recursive directory copy does not support overwriting an existing destination directory. Use conflict_resolution_strategy=rename to auto-rename, or remove the existing destination first.</Message>
<Resource>/smh26zn7j7lfnwnc-1251081331/myspace/bbb</Resource>
</Error>

Bantuan dan Dukungan

Apakah halaman ini membantu?

masukan