tencent cloud

Batch Copy Directories or Files
Last updated: 2026-01-07 14:28:06
Batch Copy Directories or Files
Last updated: 2026-01-07 14:28:06

Description

Used for batch copying directories or files.
Note:
Requires permissions. For details about permissions, see Generate Access Token API.
Copying within the same space:
admin, space_admin, or copy_directory/copy_file/copy_file_force. To copy both directories and files simultaneously, specify both copy_directory and copy_file/copy_file_force permissions.
Copying across spaces:
admin or specify space_admin for both the source space and destination space.

Request

Request Example

POST /api/v1/batch/{LibraryId}/{SpaceId}?copy&access_token={AccessToken}&user_id={UserId}

Request Parameter

Request parameters.
Description
Type
Required or Not
LibraryId
Media Library ID, obtained after creating a media library in the media hosting console. Please refer to create media library
String
Yes
SpaceId
Space ID. If the media library is in single-tenant mode, this parameter is fixed as a hyphen (-); if the media library is in multi-tenant mode, you must specify this parameter. Please refer to create tenant space for retrieval.
String
Yes
AccessToken
Access token, please refer to generate access token
String
Yes
UserId
User ID, when the access token corresponds to administrator permissions and user identity recognition during token application is empty, is used to temporarily designate user identity. For details, see generate access token
String
No

Request Body

application/json, specify the source path and path to save for copying. A single request can specify up to 1000 items.
Request body example:
[
{
"copyFromSpaceId":"spaceNJsnjdiq",
"copyFrom": "bar",
"to": "foo/bar"
},
{
"copyFrom": "foo/1.jpg",
"to": "bar/1.jpg"
},
{
"copyFrom": "foo/2.jpg",
"to": "bar/2.jpg",
"conflictResolutionStrategy": "overwrite"
}
]
Request body field description:
Request parameters.
Description
Type
Required or Not
copyFrom
Source directory, album, or file path to be copied
String
Yes
to
Destination directory, album, or file path
String
Yes
conflictResolutionStrategy
Handling method when filename conflict
ask: returns status 409 and error code SameNameDirectoryOrFileExists when conflicts with
rename: rename the file when conflicts with
overwrite:
If the target is a directory or album, it defaults to ask and does not support overwrite
If the target is a file, overwrite the existing file
When an earlier version of the file exists in the target space, do not support moving and overwriting
String
No
copyFromSpaceId
When copying across spaces, specify the space where the source directory or file resides. Do not specify this field when copying within the same space.
String
No

Response

Response code

Execution successful.
-When projects are replicated asynchronously, return HTTP 202 Accepted. - When projects are replicated synchronously, return HTTP 200 OK (all execution successful) or HTTP 207 Multi-Status (part or all execution failed).

Response Body

application/json
Response body example:
Return HTTP 200 OK or HTTP 207 Multi-Status:
{
"result": [
{
"status": 204,
"copyFrom": "bar",
"to": [ "foo", "bar" ]
},
{
"status": 200,
"path": [ "bar", "1 (1).jpg" ],
"copyFrom": [ "foo", "1.jpg" ],
"to": [ "bar", "1.jpg" ]
},
{
"status": 204,
"copyFrom": [ "foo", "2.jpg" ],
"to": [ "bar", "2.jpg" ]
}
]
}
Return HTTP 202 Accepted:
{ "taskId": 16 }
[
{
"taskId": 16,
"status": 200,
"result": [
{
"status": 204,
"copyFrom": "bar",
"to": [ "foo", "bar" ]
},
{
"status": 200,
"path": [ "bar", "1 (1).jpg" ],
"copyFrom": [ "foo", "1.jpg" ],
"to": [ "bar", "1.jpg" ]
},
{
"status": 204,
"copyFrom": [ "foo", "2.jpg" ],
"to": [ "bar", "2.jpg" ]
}
]
}
]
Response body field description:
Response Parameters
Description
Type
result.status
Copy result of individual item:
200: Copy successful when conflictResolutionStrategy is rename
204: Copy successful when conflictResolutionStrategy is ask or overwrite
403/404/409/500, copy failed
String
result.path
The final path may not equal the specified path during replication because automatic renaming may exist here.
String Array
result.copyFrom
The path passed in when making a request
String Array
result.to
The corresponding path passed in when making a request
String Array
Query task response body field description:
Response Parameters
Description
Type

status
Query task status
202: Task in progress
200: All executions successful
207: Part or all executions failed
String

Error Codes

This request operation has no special error messages. For common error messages, see Error Codes.
Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback