This topic describes the methods that you can call to perform operations on files and folders. The operations include add, delete, modify, query, copy, and move.
The options parameter of the IPDSRequestConfig type is encapsulated based on the request config options of axios. For more information, see AxiosRequestConfig.
listFiles method
You can call this method to query files or folders in a specific directory.
const result = await client.listFiles(params, options)Example
const {items=[]} = await client.listFiles({
drive_id:'1001',
parent_file_id:'root'
})Request parameters
Parameter | Type | Required | Description |
params | IListFileReq | Yes | The parameters that are used to query files or folders. |
options | IPDSRequestConfig | Other request parameters. |
IListFileReq
Parameter | Type | Required | Description |
drive_id | string | The drive ID. You must configure either the drive_id parameter or the share_id parameter. | |
share_id | string | The share ID. You must configure either the drive_id parameter or the share_id parameter. | |
parent_file_id | string | The ID of the parent directory. | |
fields | string | The parameters to be returned. If you want all the parameters to be returned, set the value to *. If you do not specify this parameter, only basic parameters are returned. By default, this parameter is not specified. | |
url_expire_sec | number | The validity period of the URL. | |
video_thumbnail_process | string | The expression that is used to process video thumbnails. For more information, see Image Processing. | |
image_thumbnail_process | string | The expression that is used to process image thumbnails. For more information, see Image Processing. | |
image_url_process | string | The expression that is used to process image URLs. For more information, see Image Processing. | |
limit | number | The maximum number of entries to be returned. | |
marker | string | The pagination token. | |
order_by | string | The parameter based on which the results are sorted. | |
order_direction | string | The order by which the results are sorted. Valid values: DESC and ASC. | |
starred | boolean | Specifies whether to add the file or folder to favorites. | |
category | string | The category of the file or folder. | |
status | string | The state of the file or folder. | |
type | string | The type of the entry. Valid values: file and folder. |
IFileItem
Parameter | Type | Required | Description |
action_list | array | The permissions. | |
category | string | The type of the file. Valid values: app, doc, image, video, audio, zip, and others. | |
content_hash | string | The identifier of the file. | |
content_hash_name | string | The encryption mode of the file. | |
content_type | string | The type of the content. | |
crc64_hash | string | The CRC-64 hash value. | |
created_at | Date | Yes | The time when the file was created. |
creator_id | string | Yes | The creator ID. |
creator_name | string | Yes | The name of the creator. |
creator_type | string | Yes | The type of the creator. Valid values: group and user. |
domain_id | string | Yes | The domain ID. |
download_url | string | The download URL. This parameter is returned only if the type parameter is set to file. | |
drive_id | string | Yes | The drive ID. |
description | string | The description of the file. | |
encrypt_mode | string | Yes | The encryption mode. |
file_extension | string | The file name extension. Example: | |
file_id | string | Yes | The folder ID. |
hidden | boolean | Yes | Indicates whether the file is hidden. |
last_modifier_id | string | Yes | The ID of the person who last modified the file. |
last_modifier_name | string | The name of the person who last modified the file. | |
last_modifier_type | string | The type of the person who modified the file. Valid values: group and user. | |
labels | string | The tags. | |
location | string | The location. | |
mime_extension | string | The extension of the media type. | |
mime_type | string | The media type. | |
meta | string | The metadata. | |
name | string | Yes | The name of the folder. |
parent_file_id | string | Yes | The ID of the parent directory. |
punish_flag | number | The number of errors. | |
revision_id | string | Yes | The revision version. |
rapid_upload | boolean | Indicates whether an instant file transfer is performed. | |
size | number | The size of the file or folder. Unit: bytes. | |
starred | boolean | Yes | Indicates whether the file or folder is added to favorites. |
status | string | Yes | The state of the file or folder. Valid values: available and uploading. |
streams_upload_info | The information about stream upload. | ||
thumbnail | string | The thumbnail. This parameter is required only if the category parameter is set to image or video. | |
type | string | Yes | The type of the entry. Valid values: file and folder. |
trashed | boolean | Indicates whether the file or folder is moved to the recycle bin. | |
updated_at | Date | Yes | The time when the file or folder was updated. |
user_meta | string | ||
upload_id | string | The upload ID. | |
url | string | The URL of the input file. |
The difference between the
download_urlparameter and theurlparameter is that thedownload_urlparameter contains the following message header:Content-Disposition: attachment; filename="filename"The message header is directly downloaded by the browser. The url parameter does not have a message header, and specific file browsers directly open the URL. For example, specific browsers can directly open pictures, MP4 videos, and PDF files.
The
thumbnailparameter is returned only for images and videos.
searchFiles method
You can call this method to search for files based on specific conditions.
const result = await client.searchFiles(params, options, isRecycleBin)Request parameters
Parameter | Type | Required | Description |
params | object | Yes | The parameters that are used to search for files. For more information, see the "ISearchFileReq" section of this topic. |
options | IPDSRequestConfig | Other request parameters. | |
isRecycleBin | boolean | Specifies whether to search for files in the recycle bin. If you want to search for the files in the recycle bin, set the value to true. Otherwise, set the value to false. Default value: false. |
ISearchFileReq
Parameter | Type | Required | Description |
limit | number | The maximum number of entries to be returned. | |
query | string | Yes | The filter conditions that are used to search for the files. For more information, see Query files. |
drive_id | string | Yes | The drive ID. |
fields | string | The parameters to be returned. If you want all the parameters to be returned, set the value to *. If you do not specify this parameter, only basic parameters are returned. By default, this parameter is not specified. | |
order_by | string | The parameter based on which the results are sorted. | |
marker | string | The pagination token. | |
url_expire_sec | number | The validity period of the URL. By default, the URL is valid for 2 hours. | |
image_thumbnail_process | string | The expression that is used to process image thumbnails. For more information, see Image Processing. | |
image_url_process | string | The expression that is used to process image URLs. For more information, see Image Processing. | |
video_thumbnail_process | string | The expression that is used to process video thumbnails. For more information, see Image Processing. |
Response parameter
Parameter | Type | Required | Description |
result | IListRes | Yes | The returned result. |
IListRes
Parameter | Type | Required | Description |
items | array | Yes | The list of files. For more information about the specific parameters, see the "IFileItem" section of this topic. |
next_marker | string | The pagination token. |
getFile method
You can call this method to query the information about a file based on the file ID.
const result = await client.getFile(params, options)Request parameters
Parameter | Type | Required | Description |
params | object | Yes | The parameters that are used to query the file information. For more information, see the "IGetFileReq" section of this topic. |
options | IPDSRequestConfig | Other request parameters. |
IGetFileReq
Parameter | Type | Required | Description |
drive_id | string | The drive ID. You must configure either the drive_id parameter or the share_id parameter. | |
share_id | string | The share ID. You must configure either the drive_id parameter or the share_id parameter. | |
file_id | string | The file ID. | |
fields | string | The parameters to be returned. If you want all the parameters to be returned, set the value to *. If you do not specify this parameter, only basic parameters are returned. By default, this parameter is not specified. | |
url_expire_sec | number | The validity period of each signed URL that is returned. | |
video_thumbnail_process | string | The expression that is used to process video thumbnails. For more information, see Image Processing. | |
image_thumbnail_process | string | The expression that is used to process image thumbnails. For more information, see Image Processing. | |
image_url_process | string | The expression that is used to process image URLs. For more information, see Image Processing. |
Response parameter
Parameter | Type | Required | Description |
result | object | Yes | The returned result. For more information, see the "IFileItem" section of this topic. |
getFileDownloadUrl
You can call this method to query the download URL of a file. Then, you can open the download URL in a browser and directly download the file.
const result = await client.getFileDownloadUrl(params, options)Example
const info = await client.getFileDownloadUrl({
drive_id: '1',
file_id: 'xxxxx',
})Request parameters
Parameter | Type | Required | Description |
params | object | Yes | The parameters that are used to query the download URL. For more information, see the "IGetFileDownloadUrlReq" section of this topic. |
options | IPDSRequestConfig | Other request parameters. |
IGetFileDownloadUrlReq
Parameter | Type | Required | Description |
drive_id | string | The drive ID. You must configure either the drive_id parameter or the share_id parameter. | |
share_id | string | The share ID. You must configure either the drive_id parameter or the share_id parameter. | |
file_id | string | The file ID. | |
fields | string | The parameters to be returned. If you want all the parameters to be returned, set the value to *. If you do not specify this parameter, only basic parameters are returned. By default, this parameter is not specified. | |
file_name | string | The name of the file to be downloaded. When the file is downloaded, the | |
expire_sec | number | The validity period of the download URL. Unit: seconds. Maximum value: 115200. Default value: 900. |
Response parameter
Parameter | Type | Required | Description |
result | object | Yes | The returned result. For more information, see the "IGetFileDownloadUrlRes" section of this topic. |
IGetFileDownloadUrlRes
Parameter | Type | Required | Description |
expiration | string | Yes | The validity period of the download URL. |
method | string | Yes | The applicable HTTP method. In most cases, the GET method is used. |
url | string | Yes | The download URL of the file. |
size | number | The size of the file. Unit: bytes. |
saveFileContent method
You can call this method to save the content of a file or create a file.
If the ID that you specify for a new file is the same as the ID of an existing file, the existing file is overwritten. If you do not specify an ID for the file, the system considers the file as a new file, and the policy that is specified by the check_name_mode parameter is used. By default, the check_name_mode parameter is set to refuse.
const result = await client.saveFileContent(params, content, config)Examples
The following sample code provides an example on how to create a file:
await client.saveFileContent({
drive_id: '1',
parent_file_id: 'root',
name: 'unnamed.txt',
content_type: 'text/plain; charset=utf-8',
}, '')The following sample code provides an example on how to modify the content of an existing file:
await client.saveFileContent(fileItem, 'modified content')Request parameters
Parameter | Type | Required | Description |
params | IGetFileReq | Yes | The information about the file. For more information, see the "IGetFileReq" section of this topic. |
content | string | The content of the file. By default, this parameter is left empty. | |
config | ISaveFileConfig | Other request parameters. |
ISaveFileConfig
Parameter | Type | Required | Description |
check_name_mode | boolean | The policy that is used when a new file has the same name as an existing file. Valid values: auto_rename: adds a random number to the end of the file name. refuse: throws an exception whose ignore: allows a new file to have the same name as an existing file. Default value: refuse. If the params parameter contains the file_id parameter, this file_id parameter becomes invalid. | |
ignore_rapid | boolean | Specifies whether to forcibly disable instant file transfer. This parameter is mainly used for testing. Default value: false. |
Response parameter
Parameter | Type | Required | Description |
result | object | Yes | The returned result. For more information, see the "IFileItem" section of this topic. |
getFileContent method
You can call this method to query the content of a file. In most cases, this method is used to read text files.
Note: If you call this method to query the content of a file, the values are directly assigned to variables. We recommend that you do not call this method to query the content of large files. Otherwise, a large amount of memory is occupied.
const result = await client.getFileContent(params, options)Request parameters
Parameter | Type | Required | Description |
params | IGetFileReq | Yes | The request parameters. |
options | IPDSRequestConfig | Other request parameters. |
The content parameter in the response is related to the options.responseType parameter. By default, the responseType parameter is set to arraybuffer. In the Node.js environment, a value of Buffer is returned for the content parameter. In the browser environment, a value of ArrayBuffer is returned for the content parameter.
If you confirm that the file is a text file, set the options.responseType parameter to text so that the returned value of the content parameter is a string.
Response parameter
Parameter | Type | Required | Description |
result | object | Yes | The returned result. |
result
Parameter | Type | Required | Description |
headers | object | Yes | The header message. |
content | Buffer | string | ... | Yes | The content of the file, which may be left empty. Different values are returned based on the value of the responseType parameter. For more information, see the "responseType" section in "axios - npm". |
size | number | Yes | The size of the file. Unit: bytes. |
type | string | Yes | The file ID. |
updated_at | string | Yes | The time when the file was updated. |
status | string | Yes | The state of the file. |
renameFile method
You can call this method to rename a file or folder.
const result = await client.renameFile(fileItem, newName,check_name_mode)Examples
The following sample code provides an example on how to rename a file:
await client.renameFile({
drive_id: "1",
file_id: 'xxxxxx',
}, 'new name.txt') Request parameters
Parameter | Type | Required | Description |
fileItem | IFileItem | Yes | The information about the file to be renamed. For more information, see the "IFileItem" section of this topic. |
newName | string | Yes | The new name of the file. |
check_name_mode | string | The policy that is used when a new file has the same name as an existing file. Valid values: auto_rename: adds a random number to the end of the file name. refuse: throws an exception whose ignore: allows a new file to have the same name as an existing file. Default value: refuse. If the fileItem parameter contains the file_id parameter, this file_id parameter becomes invalid. |
Response parameter
Parameter | Type | Required | Description |
result | object | Yes | The returned result. For more information, see the "IFileItem" section of this topic. |
updateFile method
You can call this method to modify the information about a file or folder.
const result = await client.updateFile(params, options)Request parameters
Parameter | Type | Required | Description |
params | object | Yes | The information about the file to be updated. For information about specific parameters, see the "IUpdateFileReq" section of this topic. |
options | IPDSRequestConfig | Other request parameters. |
IUpdateFileReq
Parameter | Type | Required | Description |
drive_id | string | The drive ID. You must configure either the drive_id parameter or the share_id parameter. | |
share_id | string | The share ID. You must configure either the drive_id parameter or the share_id parameter. | |
file_id | string | Yes | The file ID. |
check_name_mode | string | The policy that is used when a new file has the same name as an existing file. Valid values: auto_rename: adds a random number to the end of the file name. refuse: throws an exception whose ignore: allows a new file to have the same name as an existing file. | |
parent_file_id | string | The ID of the parent directory. | |
custom_index_key | string | The custom key. | |
description | string | The description of the file. | |
encrypt_mode | string | The encryption mode. | |
hidden | boolean | Specifies whether to hide the file or folder. | |
labels | array | The tags. | |
meta | string | ||
name | string | The name of the file or folder. | |
starred | boolean | Specifies whether to add the file or folder to favorites. | |
user_meta | string |
Response parameter
Parameter | Type | Required | Description |
result | object | Yes | The updated information. For more information about specific parameters, see the "IFileItem" section of this topic. |
getFileByPath method
You can call this method to query the information about a file or folder based on the file path.
For example, you can query a file or folder based on the path /a/b/c.
const result = await client.getFileByPath(params, options)Request parameters
Parameter | Type | Required | Description |
params | IGetFileByPathReq | Yes | The request parameters. |
options | IPDSRequestConfig | Other request parameters. |
IGetFileByPathReq
Parameter | Type | Required | Description |
drive_id | string | Yes | The drive ID. |
file_path | string | Yes | The path of the folder. Example: /a/b/c. |
fields | string | The parameters to be returned. If you want all the parameters to be returned, set the value to *. | |
url_expire_sec | number | The validity period of the URL. Unit: seconds. | |
video_thumbnail_process | string | The expression that is used to process video thumbnails. For more information, see Image Processing. | |
image_thumbnail_process | string | The expression that is used to process image thumbnails. For more information, see Image Processing. | |
image_url_process | string | The expression that is used to process image URLs. For more information, see Image Processing. |
Response parameter
Parameter | Type | Required | Description |
result | object | Yes | The returned result. For more information, see the "IFileItem" section of this topic. |
getBreadcrumbFolderList method
You can call this method to query the information about multi-level breadcrumb directories. This indicates that a pass-up recursion is performed based on the current directory to query all the associated directories. During this process, the getFile method is called.
The returned array does not contain the root directory.
Exceptions
1. If a 403 error is returned, you are forbidden to query the directory, and the query ends. In the returned array, the is_forbidden parameter is set to true for the directory.
2. If another exception occurs, the exception is directly thrown.
const result = await client.getBreadcrumbFolderList(params, options)Example
// For example, the path /a/b/c/ exists.
// The file ID of the directory c is 620cb4363a20321aa66a495ca063ac2679a8f726.
const arr = await client.getBreadcrumbFoldderList({
drive_id,
file_id,
})
// Return the information about multi-level breadcrumb directories: [{file_id: 'ID of Directory a', name:'a'},{file_id: 'ID of Directory b', name:'b'}].
Request parameters
Parameter | Type | Required | Description |
params | IGetBreadcrumbReq | Yes | The parameters that are used to query the information about multi-level breadcrumb directories. |
options | IPDSRequestConfig | Other request parameters. |
IGetBreadcrumbReq
Parameter | Type | Required | Description |
drive_id | string | The drive ID. You must configure either the drive_id parameter or the share_id parameter. | |
share_id | string | The share ID. You must configure either the drive_id parameter or the share_id parameter. | |
file_id | string | Yes | The ID of the current directory. |
end_parent_id | string | The ID of the parent directory at which you want to end the query. Default value: root. |
Response parameter
Parameter | Type | Required | Description |
result | IParentFolderNameId[] | Yes | The returned result. |
IParentFolderNameId
Parameter | Type | Required | Description |
file_id | string | Yes | The ID of the directory. |
name | string | Yes | The name of the directory. |
is_forbidden | boolean | Indicates whether you are forbidden to query the directory. |
getBreadcrumbFolders method
We recommend that you replace this method with the getBreadcrumbFolderList method.
You can call this method to query the information about multi-level breadcrumb directories. This indicates that a pass-up recursion is performed based on the current directory to query all the associated directories. During this process, the getFile method is called.
The returned array does not contain the root directory.
Exceptions
1. If a 403 error is returned, you are forbidden to query the directory, and the query ends. In the returned array, the is_forbidden parameter is set to true for the directory.
2. If another exception occurs, the exception is directly thrown.
const result = await client.getBreadcrumbFolders(drive_id,file_id, end_parent_id)Request parameters
Parameter | Type | Required | Description |
drive_id | string | Yes | The drive ID. |
file_id | string | Yes | The directory ID. |
end_parent_id | string | The ID of the parent directory at which you want to end the query. Default value: root. |
Response parameter
Parameter | Type | Required | Description |
result | IParentFolderNameId[] | Yes | The returned result. |
IParentFolderNameId
Parameter | Type | Required | Description |
file_id | string | Yes | The ID of the directory. |
name | string | Yes | The name of the directory. |
is_forbidden | boolean | Indicates whether you are forbidden to query the directory. |
createFolder method
You can call this method to create a folder.
const result = await client.createFolder(params, options)Example
await client.createFolder({
name: 'new folder',
drive_id: '1',
parent_file_id: 'root',
// check_name_mode:'auto_rename'
})Request parameters
Parameter | Type | Required | Description |
params | ICreateFolderReq | Yes | The parameters that are used to create a folder. For more information, see the |
options | IPDSRequestConfig | No | Other request parameters. |
ICreateFolderReq
Parameter | Type | Required | Description |
check_name_mode | string | The policy that is used when a new file has the same name as an existing file. Valid values: auto_rename: adds a random number to the end of the file name. refuse: throws an exception whose ignore: allows a new file to have the same name as an existing file. Default value: refuse. | |
drive_id | string | The drive ID. You must configure either the drive_id parameter or the share_id parameter. | |
share_id | string | The share ID. This parameter is valid for sharelink. You must configure either the drive_id parameter or the share_id parameter. | |
name | string | Yes | The name of the directory. |
parent_file_id | string | Yes | The ID of the parent directory. If the directory is the root directory, set the value to root. |
Response parameter
Parameter | Type | Required | Description |
result | ICreateFolderRes | Yes | The returned result. |
ICreateFolderRes
Parameter | Type | Required | Description |
domain_id | string | Yes | The domain ID. |
drive_id | string | The drive ID. You must configure either the drive_id parameter or the share_id parameter. | |
share_id | string | The share ID. You must configure either the drive_id parameter or the share_id parameter. | |
encrypt_mode | string | The encryption mode. | |
file_id | string | Yes | The file ID. |
file_name | string | Yes | The name of the file. |
parent_file_id | string | Yes. | The ID of the parent directory. If the directory is the root directory, set the value to root. |
type | string | Yes | The type of the entry. Valid values: file and folder. |
Example
{
"parent_file_id": "root",
"type": "folder",
"file_id": "61ba1892abbe9f56bb7342c4beee82156e68dd67",
"domain_id": "daily123",
"drive_id": "1",
"file_name": "new folder",
"encrypt_mode": "none"
}createFolders method
You can call this method to create folders. if a new folder has the same name as an existing folder, the policy that is specified by the check_name_mode parameter is used.
const result = await client.createFolders(folderNames, parentKey, config)Request parameters
Parameter | Type | Required | Description |
folderNames | string[] | Yes | The names of folders. For example, if you want to create a directory whose path is a/b/c, set the value to ['a', 'b', 'c' ]. |
parentKey | IParentFileKey | Yes | The parameters that are used to create multi-level folders. |
config | ICreateFoldersConfig | Optional request parameters. |
IParentFileKey
Parameter | Type | Required | Description |
drive_id | string | The drive ID. You must configure either the drive_id parameter or the share_id parameter. | |
share_id | string | The share ID. You must configure either the drive_id parameter or the share_id parameter. | |
parent_file_id | string | Yes | The ID of the parent directory. If the directory is the root directory, set the value to root. |
ICreateFoldersConfig
Parameter | Type | Required | Description |
check_name_mode | string | The policy that is used when a new file has the same name as an existing file. Valid values: auto_rename: adds a random number to the end of the file name. refuse: calls back the ignore: allows a new file to have the same name as an existing file. overwrite: overwrites an existing file with a file that has the same name as the existing file. skip: skips the files that have the same name. Default value: refuse. | |
create_folder_cache | Map<string, any>={} | The map method, which caches the directory information. | |
onFolderRepeat | ()=>boolean | The callback that is invoked if the path that you specify exists. If a value of | |
onFolderCreated | (fileItem)=>void | The callback that is invoked if the creation is successful. |
Response parameter
Parameter | Type | Required | Description |
result | string | Yes | The path that is created. |
deleteFile method
You can call this method to delete a specific file or folder.
await client.deleteFile(params, permanently, options)Request parameters
Parameter | Type | Required | Description |
params | IFileKey | Yes | The information about the file or folder to be deleted. |
permanently | boolean | Specifies whether to permanently delete the file or folder. A value of false indicates that the file or folder is temporarily removed and can be restored. A value of true indicates that the file or folder is permanently deleted. Default value: false. | |
options | IPDSRequestConfig | Other request parameters. |
IFileKey
Parameter | Type | Required | Description |
share_id | string | The share ID. You must configure either the drive_id parameter or the share_id parameter. | |
drive_id | string | The drive ID. You must configure either the drive_id parameter or the share_id parameter. | |
file_id | string | The ID of the file or folder to be deleted. |
Response parameters
If a single file is deleted, the HTTP status code 204 may be directly returned, and the response body is empty.
If a folder is deleted, a JSON structure that consists of the HTTP status code 202 and response parameters may be returned. The following table describes the response parameters.
Parameter | Type | Required | Description |
async_task_id | string | The ID of the asynchronous task. | |
domain_id | string | The drive ID. | |
file_id | string | The ID of the file or folder that is deleted. |
batchDeleteFiles method
You can call this method to delete multiple files or folders at a time.
const result = await client.batchDeleteFiles(params, permanently, options)Request parameters
Parameter | Type | Required | Description |
params | IFileKey[] | Yes | The information about the files or folders to be deleted. You can delete multiple files or folders at a time. For more information about specific parameters, see the "successArr" and "errorArr" sections of this topic. You need to only pass in a file ID or directory ID. This method automatically performs a recursion to delete all the files that reside in the directory. |
permanently | boolean | Yes | Specifies whether to permanently delete the files or folders. A value of false indicates that the files or folders are temporarily removed and can be restored. A value of true indicates that the files or folders are permanently deleted. Default value: false. |
options | IPDSRequestConfig | No | Other request parameters. |
Response parameter
Parameter | Type | Required | Description |
result | object | Yes | The returned result. If the files or folders are deleted, successArr is returned. If the files or folders fail to be deleted, errorArr is returned. |
successArr
If files are deleted, the value of the successArr parameter is undefined. If folders are deleted, the returned result contains the following parameters.
Parameter | Type | Required | Description |
async_task_id | string | Yes | The ID of the asynchronous task. |
domain_id | string | Yes | The domain ID. |
drive_id | string | Yes | The drive ID. |
share_id | string | The share ID. | |
file_id | string | Yes | The ID of the file or folder that is deleted. |
errorArr
If the files or folders fail to be deleted, the file information that you specify is returned.
Parameter | Type | Required | Description |
share_id | string | The share ID. | |
drive_id | string | Yes | The drive ID. |
file_id | string | Yes | The ID of the file or folder that fails to be deleted. |
copyFiles method
You can call this method to copy files or folders.
const result = await client.copyFiles(params, config, options)Examples
The following sample code provides an example on how to copy multiple files:
const {items=[]} = await client.listFiles(req)
// Pass in the fileItem array.
await client.copyFiles(items, {to_parent_file_id, to_drive_id})When you copy a single file, you can rename the file by running the following sample code:
await client.copyFiles(item, { new_name: 'new file name', ... })You can run the following sample code to cancel the copy operation during the copy process:
let stopFlag=false
// The method that is used to cancel the copy operation.
function cancel(){
stopFlag=true
}
await client.copyFiles(items, {
getStopFlag()=>{
return stopFlag
}
})Request parameters
Parameter | Type | Required | Description |
params | IFileItemKey[] | Yes | The files to be copied. For more information about specific parameters, see the "IFileKey" section of this topic. |
config | ICopyFilesConfig | Yes | The configurations related to copying files. |
options | IPDSRequestConfig | Other request parameters. |
IFileItemKey
Parameter | Type | Required | Description |
drive_id | string | The drive ID. You must configure either the drive_id parameter or the share_id parameter. | |
share_id | string | The share ID. You must configure either the drive_id parameter or the share_id parameter. | |
file_id | string | Yes | The ID of the file or folder. |
parent_file_id | string | Yes | The ID of the parent directory. |
ICopyFilesConfig
Parameter | Type | Required | Description |
to_parent_file_id | string | Yes | The ID of the folder to which the file is copied. |
to_drive_id | string | The ID of the drive to which the file is copied. You must configure either the drive_id parameter or the share_id parameter. | |
to_share_id | string | The ID of the share to which the file is copied. You must configure either the drive_id parameter or the share_id parameter. | |
new_name | string | The new name of the file. You can specify this parameter only when you copy a single file. | |
onProgress | (count,totoal)=>{} | The callback parameter of the copy progress, which contains two parameters: count and total. | |
getStopFlag | ()=>boolean | Specifies whether to stop the copy process. A value of true specifies that the copy process is to be stopped. A value of false specifies that the copy process is to be continued. |
Response parameter
Parameter | Type | Required | Description |
result | ICopyFileRes[] | Yes | The returned result. |
ICopyFileRes
Parameter | Type | Required | Description |
async_task_id | string | The ID of the asynchronous task. This parameter is available only if you copy folders. | |
domain_id | string | The domain ID. | |
drive_id | string | The drive ID. You must configure either the drive_id parameter or the share_id parameter. | |
share_id | string | The share ID. You must configure either the drive_id parameter or the share_id parameter. | |
file_id | string | Yes | The file ID. |
moveFiles method
You can call this method to move files or folders.
const result = await client.moveFiles(params, config, options)Examples
The following sample code provides an example on how to move multiple files:
const {items=[]} = await client.moveFiles(...)
// Pass in the fileItem array.
await client.moveFiles(items, {to_parent_file_id, to_drive_id })When you move a single file, you can rename the file by running the following sample code:
await client.moveFiles(item, { new_name: 'new file name', ... })You can run the following sample code to cancel the move operation during the move process:
let stopFlag=false
// The method that is used to cancel the move operation.
function cancel(){
stopFlag=true
}
await client.moveFiles(items, {
getStopFlag()=>{
return stopFlag
}
})Request parameters
Parameter | Type | Required | Description |
params | IFileItemKey[] | Yes | The files to be moved. For more information about specific parameters, see the "IFileKey" section of this topic. |
config | ICopyFilesConfig | Yes | The configurations related to moving files. For more information, see the "copyFiles method" section of this topic. |
options | IPDSRequestConfig | Other request parameters. |
Response parameter
Parameter | Type | Required | Description |
result | ICopyFileRes[] | Yes | The returned result. For more information, see the response parameters of the copyFiles method. |
getAsyncTask method
You can call this method to query the progress of a task.
const result = await client.getAsyncTask(async_task_id, options)Request parameters
Parameter | Type | Required | Description |
async_task_id | string | Yes | The task ID. |
options | IPDSRequestConfig | Other request parameters. |
Response parameter
Parameter | Type | Required | Description |
result | object | Yes | The returned result. For more information, see the "IAsyncTaskRes" section of this topic. |
IAsyncTaskRes
Parameter | Type | Required | Description |
async_task_id | string | Yes | The ID of the asynchronous task. |
state | string | Yes | The state of the task. Valid values: Failed, Success, PartialSucceed, and Running. |
error_message | string | The message. | |
error_code | number | The message that is returned when the task is in the Failed state. | |
url | string | The download URL that is returned by the archiveFile operation after the file is archived. |
pollingAsyncTask method
You can call this method to poll the progress of the task on a regular basis until the desired result is returned.
const result = await client.getAsyncTask(async_task_id, ttl_ms options)Request parameters
Parameter | Type | Required | Description |
async_task_id | string | Yes | The task ID. |
ttl_ms | number | The interval at which a poll is performed. Unit: millisecond. Default value: 5000. | |
options | IPDSRequestConfig | Other request parameters. |
Response parameter
Parameter | Type | Required | Description |
result | IAsyncTaskRes | Yes | The returned result. |