File operations

Updated at:

This topic describes methods for performing file operations, including creating, reading, updating, deleting, copying, and moving files. In all the methods described below, the options parameter specifies additional request configurations. For more information, see AxiosRequestConfig.

listFiles method

Note

Supported in standard and hosting modes.

This method lists the files or folders in a specified directory.

const result = await client.listFiles(params, options)

Example

const {items=[]} = await client.listFiles({
  drive_id:'1001', 
  parent_file_id:'root'
})

Parameters

Parameter

Type

Required

Description

params

IListFileReq

Yes

Query parameters

options

AxiosRequestConfig

Other configuration items

IListFileReq

Parameter

Type

Required

Description

drive_id

string

(Required in standard mode)

The disk ID. `drive_id` and `share_id` are mutually exclusive. You must specify one.

share_id

string

(In hosting mode, `drive_id` and `share_id` are mutually exclusive. You must specify one.)

The share ID. Supported in hosting mode. `drive_id` and `share_id` are mutually exclusive. You must specify one.

parent_file_id

string

(Required in standard mode)

The parent directory ID.

parent_file_path

string

(Required in hosting mode)

The parent file path.

fields

string

The file fields to return. To return all fields, enter "*". If you do not specify this parameter, only basic fields are returned. Default: Not specified.

url_expire_sec

number

The validity period of the URL.

video_thumbnail_process

string

The expression for video thumbnail processing. For more information, see Image processing.

image_thumbnail_process

string

The expression for image thumbnail processing. For more information, see Image processing.

image_url_process

string

The expression for image URL processing. For more information, see Image processing.

limit

number

The maximum number of items to return.

marker

string

The pagination token.

order_by

string

The field to sort by.

order_direction

string

Valid values: 'DESC' | 'ASC'

starred

boolean

Indicates whether the file is starred.

category

string

Category

status

string

Status

type

string

The file type. Valid values: 'file' | 'folder'

IFileItem (return value for HostingMode)

Parameter

Type

Required

Description

content_type

string

Content type

domain_id

string

Yes

Domain ID

download_url

string

Yes

The download URL. This is returned only for files.

drive_id

string

The disk ID.

file_extension

string

File name extension

file_path

string

Yes

File path

name

string

Yes

Name

parent_file_path

string

Yes

Parent directory

size

number

Yes

The file size in bytes.

status

string

Yes

Valid values: 'available' | 'uploading'

share_id

string

Share ID

thumbnail

string

The thumbnail URL.

type

string

Yes

The file type. Valid values:

updated_at

Date

The time when the file was last updated.

url

string

File URL

IFileItem (return value for StandardMode)

Field

Type

Required

Description

action_list

array

Permission list

category

string

The file category. Valid values: doc | image | video | audio | zip | others

content_hash

string

File Identity

content_hash_name

string

The hashing algorithm used.

content_type

string

Content type

crc64_hash

string

The CRC64 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 creator name.

creator_type

string

Yes

The creator type. Valid values: 'group' | 'user'

domain_id

string

Yes

Domain ID

download_url

string

The download URL. This is returned for files.

drive_id

string

Yes

The disk ID.

description

string

Description

encrypt_mode

string

Yes

Encryption mode

file_extension

string

The file name extension, such as .txt.

file_id

string

Yes

Folder ID

hidden

boolean

Yes

Indicates whether the file is hidden.

last_modifier_id

string

Yes

The ID of the user who last modified the file.

last_modifier_name

string

The name of the user who last modified the file.

last_modifier_type

string

The type of the user who last modified the file. Valid values: 'group' | 'user'

labels

string

Tags

location

string

Location

mime_extension

string

MIME extension

mime_type

string

MIME type

meta

string

Cloud information

name

string

Yes

Folder name

parent_file_id

string

Yes

The parent directory ID.

punish_flag

number

The number of errors.

revision_id

string

Yes

Revision History

rapid_upload

boolean

Indicates whether rapid upload is enabled.

size

number

The file size in bytes.

starred

boolean

Yes

Indicates whether the file is starred.

status

string

Yes

Valid values: 'available' | 'uploading'

streams_upload_info

Stream upload information

thumbnail

string

This applies only to files.

type

string

Yes

The file type. Valid values: 'file' | 'folder'

trashed

boolean

Indicates whether the file has been moved to the recycle bin.

updated_at

Date

Yes

The time when the file was last updated.

user_meta

string

upload_id

string

Upload ID

url

string

Original file URL

  • The difference between download_url and url is that download_url adds a

    Content-Disposition: attachment; filename="filename"

    header. This header prompts the browser to download the file directly. The url does not include this header, which allows browsers to open some files directly, such as images, MP4 videos, and PDFs.

  • thumbnail: Only files such as images and videos have thumbnails.

searchFiles method

Important

Supported only in standard mode, not in hosting mode.

This method searches for files based on specified criteria.

const result = await client.searchFiles(params, options, isRecycleBin)

Parameters

Parameter

Type

Required

Description

params

object

Yes

The search parameters. For more information, see ISearchFileReq.

options

AxiosRequestConfig

Other configuration items

isRecycleBin

boolean

Set to true to search the recycle bin. Set to false for other searches. Default: false.

ISearchFileReq

Parameter

Type

Required

Description

limit

number

The maximum number of items to return.

query

string

Yes

The conditional statement for filtering. For usage details, see File search.

drive_id

string

Yes

The disk ID.

fields

string

The file fields to return. To return all fields, enter "*". If you do not specify this parameter, only basic fields are returned. Default: Not specified.

order_by

string

The field to sort by.

marker

string

The pagination token.

url_expire_sec

number

The validity period of the URL. Default: 2 hours.

image_thumbnail_process

string

The expression for image thumbnail processing. For more information, see Image processing.

image_url_process

string

The expression for image URL processing. For more information, see Image processing.

video_thumbnail_process

string

The expression for video thumbnail processing. For more information, see Image processing.

Return value

Parameter

Type

Required

Description

result

IListRes

Yes

The returned result.

IListRes

Parameter

Type

Required

Description

items

array

Yes

A list of files. For information about the fields for each item, see the IFileItem (StandardMode) return value in the listFiles method.

next_marker

string

The pagination token.

getFile method

Note

Supported in standard and hosting modes.

This method queries for file information by file ID.

const result = await client.getFile(params, options)

Parameters

Parameter

Type

Required

Description

params

object

Yes

The query parameters. See the IGetFileReq type.

options

AxiosRequestConfig

Other configuration items

IGetFileReq

Parameter

Type

Required

Description

drive_id

string

(Required in standard mode)

The disk ID. `drive_id` and `share_id` are mutually exclusive. You must specify one.

share_id

string

(In hosting mode, `drive_id` and `share_id` are mutually exclusive. You must specify one.)

The share ID. Supported in hosting mode. `drive_id` and `share_id` are mutually exclusive. You must specify one.

file_id

string

(Required in standard mode)

The file ID.

file_path

string

(Required in hosting mode)

File path

fields

string

The file fields to return. To return all fields, enter "*". If you do not specify this parameter, only basic fields are returned. Default: Not specified.

url_expire_sec

number

The validity period of the signed URLs that are returned.

video_thumbnail_process

string

The expression for video thumbnail processing. For more information, see Image processing.

image_thumbnail_process

string

The expression for image thumbnail processing. For more information, see Image processing.

image_url_process

string

The expression for image URL processing. For more information, see Image processing.

Return value

Parameter

Type

Required

Description

result

object

Yes

The returned result. For more information, see the IFileItem type.

getFileDownloadUrl

Added in v0.1.3

Note

Supported in standard and hosting modes.

This method retrieves the download_url of a file. When you open the download_url in a browser, the file download starts immediately.

const result = await client.getFileDownloadUrl(params, options)

Example

const info = await client.getFileDownloadUrl({
  drive_id: '1',
  file_id: 'xxxxx'
})

Parameters

Parameter

Type

Required

Description

params

object

Yes

The query parameters. See the IGetFileDownloadUrlReq type.

options

AxiosRequestConfig

Other configuration items

IGetFileDownloadUrlReq

Parameter

Type

Required

Description

drive_id

string

(Required in standard mode)

The disk ID. `drive_id` and `share_id` are mutually exclusive. You must specify one.

share_id

string

(In hosting mode, `drive_id` and `share_id` are mutually exclusive. You must specify one.)

The share ID. Supported in hosting mode. `drive_id` and `share_id` are mutually exclusive. You must specify one.

file_id

string

(Required in standard mode)

The file ID.

file_path

string

(Required in hosting mode)

File path

fields

string

The file fields to return. To return all fields, enter "*". If you do not specify this parameter, only basic fields are returned. Default: Not specified.

Returns

Parameter

Type

Required

Description

result

object

Yes

The returned result. For more information, see the IGetFileDownloadUrlRes type.

IGetFileDownloadUrlRes

Parameter

Type

Required

Description

expiration

string

Yes

The expiration time.

method

string

Yes

The applicable HTTP method. This is usually GET.

url

string

Yes

The file download URL.

size

number

The file size in bytes.

saveFileContent method

Note

Supported in standard and hosting modes.

This method saves content to a file or creates a new file.

In hosting mode, an existing file with the same name is overwritten.

In standard mode, if you provide an existing file ID, the file is overwritten. If you do not provide a file ID, a new file is created based on the policy specified by the check_name_mode parameter. The default value of check_name_mode is 'refuse'.

const result = await client.saveFileContent(params, content, config)

Examples

Create an empty file

await client.saveFileContent({
  drive_id: '1',
  parent_file_id: 'root',
  name: 'Untitled.txt',
  content_type: 'text/plain; charset=utf-8',
}, '')

Modify the content of an existing file

await client.saveFileContent(fileItem, 'Modified content')

Parameters

Parameter

Type

Required

Description

params

IGetFileReq

Yes

The file information. See the IGetFileReq type.

content

string

The file content. Default: empty string ''.

config

ISaveFileConfig

Other configurations

ISaveFileConfig

Parameter

Type

Required

Description

check_name_mode

boolean

(Valid in standard mode) The policy for handling files with the same name. Valid values:

auto_rename: Appends a random number to the file name.

refuse: Throws an exception with the code AlreadyExists.

ignore: Allows files with the same name.

Default: refuse.

If the first parameter contains the file_id field, this field is ignored.

ignore_rapid

boolean

(Valid in standard mode, mainly for testing) Forces the system to not use rapid upload. Default: false.

Return value

Parameter

Type

Required

Description

result

object

Yes

The returned result. For more information, see the IFileItem type.

getFileContent method

Note

Supported in standard and hosting modes.

This method retrieves the content of a file. This method is typically used to read text files.

Note: This method assigns the file content directly to a variable. Do not use this method for large files because it can consume a large amount of memory.

const result = await client.getFileContent(params, options)

Parameters

Parameter

Type

Required

Description

params

IGetFileReq

Yes

Request parameters

options

AxiosRequestConfig

Other request parameters

  • The content field in the return value depends on the `options.responseType` parameter. The default `responseType` is `arraybuffer`, which returns the content as a Buffer (for Node.js) or an ArrayBuffer (for browsers).

  • If you are certain that the file is a text file, set `options.responseType` to `text`. The returned content will then be a string.

Return value

Parameter

Type

Required

Description

result

object

Yes

The returned result.

result

Parameter

Type

Required

Description

headers

object

Yes

Response header information

content

Buffer | string | ...

Yes

The content information. This can be empty. The format of the returned content depends on the responseType setting. For more information, see the axios responseType documentation.

size

number

Yes

The file size in bytes.

type

string

Yes

The file ID.

updated_at

string

Yes

The time when the file was last updated.

status

string

Yes

Status

renameFile method

Note

Supported in standard and hosting modes.

Rename a file or folder

const result = await client.renameFile(fileItem, newName,check_name_mode)

Examples

Standard mode:

await client.renameFile({
  drive_id: "1",
  file_id: 'xxxxxx',
}, 'new_name.txt')

Hosting mode:

await client.renameFile({
  drive_id: "1",
  file_path: '/a.jpg',
}, 'new_name.jpg')

Parameters

Parameter

Type

Required

Description

fileItem

IFileItem

Yes

The information of the file to rename. See the IFileItem type.

newName

string

Yes

The new name.

check_name_mode

string

(Valid in standard mode) The policy for handling files with the same name. Valid values:

auto_rename: Appends a random number to the file name.

refuse: Throws an exception with the code AlreadyExists.

ignore: Allows files with the same name.

Default: refuse.

If the first parameter contains the file_id field, this field is ignored.

Return value

Parameter

Type

Required

Description

result

object

Yes

The returned result. See the IFileItem type.

  • In hosting mode, if a file with the same name exists, an exception with the code AlreadyExists is thrown.

updateFile method

Important

Supported only in standard mode, not in hosting mode.

This method modifies the information of a file or folder.

const result = await client.updateFile(params, options)

Parameters

Parameter

Type

Required

Description

params

object

Yes

The file information to update. For information about the fields, see IUpdateFileReq.

options

AxiosRequestConfig

Other configuration items

IUpdateFileReq

Parameter

Type

Required

Description

drive_id

string

Yes

The disk ID. `drive_id` and `share_id` are mutually exclusive. You must specify one.

file_id

string

Yes

The file ID.

check_name_mode

string

The policy for handling files with the same name. Valid values:

auto_rename: Appends a random number to the file name.

refuse: Throws an exception with the code AlreadyExists.

ignore: Allows files with the same name.

parent_file_id

string

The parent directory ID.

custom_index_key

string

Custom key

description

string

Description

encrypt_mode

string

Encryption mode

hidden

boolean

Indicates whether the file is hidden.

labels

array

Tags

meta

string

name

string

Name

starred

boolean

Indicates whether the file is starred.

user_meta

string

Return value

Parameter

Type

Required

Description

result

object

Yes

The updated information. For information about the fields for each item, see the IFileItem type in the listFiles method.

getFileByPath method

Important

Supported only in standard mode, not in hosting mode.

This method retrieves the information of a file or folder by its path.

For example, get the item information for a file at the path /a/b/c.

const result = await client.getFileByPath(params, options)

Parameters

Parameter

Type

Required

Description

params

IGetFileByPathReq

Yes

Parameters

options

AxiosRequestConfig

Other configuration items

IGetFileByPathReq

Parameter

Type

Required

Description

drive_id

string

Yes

The drive ID.

file_path

string

Yes

The folder path, for example, '/a/b/c'.

fields

string

File type: All files (*)

url_expire_sec

number

The validity period of the URL.

video_thumbnail_process

string

The expression for video thumbnail processing. For more information, see Image processing.

image_thumbnail_process

string

The expression for image thumbnail processing. For more information, see Image processing.

image_url_process

string

The expression for image URL processing. For more information, see Image processing.

Return value

Parameter

Type

Required

Description

result

object

Yes

The returned result. For more information, see the IFileItem type.

getBreadcrumbFolderList method

Added in v0.1.7

Important

Supported only in standard mode, not in hosting mode.

Retrieve multi-level breadcrumb directory information: Recursively search upwards from the current directory by calling the getFile interface.

The returned array does not include the root directory.

Exceptions

* 1. If the search encounters a directory that you do not have permission to access (403), the search stops. The returned array includes a directory item where is_forbidden==true.

* 2. An error is thrown for any other exception.

const result = await client.getBreadcrumbFolderList(params, options)

Example

// Assume the directory is /a/b/c/
// The file_id of directory c is "620cb4363a20321aa66a495ca063ac2679a8f726"

const arr = await client.getBreadcrumbFoldderList({
  drive_id,
  file_id,
})
// Returns multi-level breadcrumb directory information: [{file_id:'ID of directory a', name:'a'},{file_id:'ID of directory b', name:'b'}]

Parameters

Parameter

Type

Required

Description

params

IGetBreadcrumbReq

Yes

Parameters

options

AxiosRequestConfig

Other configuration items

IGetBreadcrumbReq

Parameter

Type

Required

Description

drive_id

string

(`drive_id` and `share_id` are mutually exclusive. You must specify one.)

The disk ID. `drive_id` and `share_id` are mutually exclusive. You must specify one.

share_id

string

(`drive_id` and `share_id` are mutually exclusive. You must specify one.)

The share ID. `drive_id` and `share_id` are mutually exclusive. You must specify one.

file_id

string

Yes

The current directory ID.

end_parent_id

string

The ID of the parent directory at which to stop the search. Default: root.

Returns

Parameter

Type

Required

Description

result

IParentFolderNameId[]

Yes

The returned result.

IParentFolderNameId

Parameter

Type

Required

Description

file_id

string

Yes

The file ID of the directory.

name

string

Yes

The directory name.

is_forbidden

boolean

This is true if a directory is encountered for which you do not have query permissions.

getBreadcrumbFolders method

Important
  • This method is not recommended. Use the getBreadcrumbFolderList method instead.

  • This method is supported only in standard mode, not in hosting mode.

Get multi-level breadcrumb information by calling the getFile interface to recursively search upwards from the current directory.

The returned array does not include the root directory.

Exceptions

* 1. If the search encounters a directory that you do not have permission to access (403), the search stops. The returned array includes a directory item where the is_forbidden property is true.

* 2. For all other exceptions, an error is thrown.

const result = await client.getBreadcrumbFolders(drive_id,file_id, end_parent_id)

Parameters

Parameter

Type

Required

Description

drive_id

string

Yes

The current disk ID.

file_id

string

Yes

The current directory ID.

end_parent_id

string

The ID of the parent directory at which to stop the search. Default: root.

Return value

Parameter

Type

Required

Description

result

IParentFolderNameId[]

Yes

The returned result.

IParentFolderNameId

Parameter

Type

Required

Description

file_id

string

Yes

The file ID of the directory.

name

string

Yes

The directory name.

is_forbidden

boolean

This is true if a directory is encountered for which you do not have query permissions.

createFolder method

Note

Supported in standard and hosting modes

This method creates a directory (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'
})

Parameters

Parameter

Type

Required

Description

params

ICreateFolderReq

Yes

See the ICreateFolderReq type.

options

AxiosRequestConfig

No

Other configuration items

ICreateFolderReq

Parameter

Type

Required

Description

check_name_mode

string

(Valid in standard mode) The policy for handling files with the same name. Valid values:

auto_rename: Appends a random number to the file name.

refuse: Throws an exception with the code AlreadyExists.

ignore: Allows files with the same name.

Default: refuse.

drive_id

string

(Required in standard mode)

The disk ID. `drive_id` and `share_id` are mutually exclusive. You must specify one.

share_id

string

(Valid in hosting mode. `drive_id` and `share_id` are mutually exclusive. You must specify one.)

The share ID. Valid in hosting mode. `drive_id` and `share_id` are mutually exclusive. You must specify one.

name

string

Yes

The directory name.

parent_file_id

string

(Required in standard mode)

The parent file ID. For the root path, enter root.

parent_file_path

string

(Required in hosting mode)

The parent file path.

Return value

Parameter

Type

Required

Description

result

ICreateFolderRes

Yes

The returned result.

ICreateFolderRes

Parameter

Type

Required

Description

domain_id

string

Yes

Domain ID

drive_id

string

The disk ID.

share_id

string

The share ID. Valid in hosting mode.

encrypt_mode

string

The encryption mode. Valid in standard mode.

file_id

string

(Required in standard mode)

The file ID.

file_path

string

(Required in hosting mode)

File path

file_name

string

Yes

File name

parent_file_id

string

(Required in standard mode)

The parent file ID. For the root path, enter root. Valid in standard mode.

type

string

Yes

The file type. Valid values: 'file' | 'folder'.

Example:

{
  "parent_file_id": "root",
  "type": "folder",
  "file_id": "61ba1892abbe9f56bb7342c4beee82156e68dd67",
  "domain_id": "daily123",
  "drive_id": "1",
  "file_name": "New Folder",
  "encrypt_mode": "none"
}
{
  "type":"folder",
  "file_path":"/New Folder 2/",
  "domain_id":"hz63",
  "drive_id":"4801"
}

createFolders method

Note

Supported in standard and hosting modes

If a folder with the same name exists, it is overwritten in hosting mode. In standard mode, the action taken depends on the check_name_mode policy.

const result = await client.createFolders(folderNames, parentKey, config)

Parameters

Parameter

Type

Required

Description

folderNames

string[]

Yes

The directory names. For example, to create the directory 'a/b/c', pass ['a', 'b', 'c'].

parentKey

IParentFileKey

Yes

Parameters for creating multi-level folders.

config

ICreateFoldersConfig

Optional configuration parameters.

IParentFileKey

Parameter

Type

Required

Description

drive_id

string

The disk ID.

share_id

string

The share ID. Valid in hosting mode.

parent_file_id

string

(Required in standard mode)

The parent directory ID. The root directory is root.

parent_file_path

string

(Required in hosting mode)

The parent directory path. The root directory is /.

ICreateFoldersConfig

Parameter

Type

Required

Description

check_name_mode

string

(Valid in standard mode) The policy for handling files with the same name. Valid values:

auto_rename: Appends a random number to the file name.

refuse: Invokes the onFolderRepeat callback.

ignore: Allows files with the same name.

Default: refuse.

create_folder_cache

Map<string, any>={}

A map to cache directory information.

onFolderRepeat

()=>boolean

(Valid in standard mode) A callback that is invoked when the path is found to exist. If it returns true, the process continues. If it returns false, an error with the code AlreadyExists is thrown.

onFolderCreated

(fileItem)=>void

A callback that is invoked upon successful creation.

Return value

Parameter

Type

Required

Description

result

string

Yes

The path that was successfully created.

deleteFile method

Note

Supported in standard and hosting modes.

This method deletes a specified file or folder.

await client.deleteFile(params, permanently, options)

Parameters

Parameter

Type

Required

Description

params

IFileKey

Yes

The information of the file to delete.

permanently

boolean

Specifies whether to permanently delete the file. `false` indicates a soft delete. `true` indicates a permanent delete. Default: `false`. (Hosting mode does not support soft delete.)

options

AxiosRequestConfig

Other configuration items

IFileKey

Parameter

Type

Required

Description

share_id

string

(Valid in hosting mode. `drive_id` and `share_id` are mutually exclusive. You must specify one.)

The share ID. `drive_id` and `share_id` are mutually exclusive. You must specify one.

drive_id

string

(Required in standard mode)

The disk ID. `drive_id` and `share_id` are mutually exclusive. You must specify one.

file_id

string

(Required in standard mode)

The ID of the file or folder to delete.

file_path

string

(Required in hosting mode)

The path of the file or folder to delete.

Returns

In standard mode, the following fields are returned:

Parameter

Type

Required

Description

async_task_id

string

(Valid in hosting mode. `drive_id` and `share_id` are mutually exclusive. You must specify one.)

The share ID. `drive_id` and `share_id` are mutually exclusive. You must specify one.

domain_id

string

(Required in standard mode)

The disk ID. `drive_id` and `share_id` are mutually exclusive. You must specify one.

file_id

string

(Required in standard mode)

The ID of the file or folder to delete.

In hosting mode, nothing is returned.

batchDeleteFiles method

Note

Supported in standard and hosting modes.

This method deletes specified files or folders in a batch.

const result = await client.batchDeleteFiles(params, permanently, options)

Parameters

Parameter

Type

Required

Description

params

IFileKey[]

Yes

A list of files to delete. Batch deletion is supported. For information about the fields for each item, see the description of IBatchFileReq. (Note: You only need to pass the file or directory IDs to delete. The method automatically and recursively deletes all files within a specified directory.)

permanently

boolean

Yes

Specifies whether to permanently delete the file. `false` indicates a soft delete. `true` indicates a permanent delete. Default: `false`. (Hosting mode does not support soft delete.)

options

AxiosRequestConfig

No

Other configuration items

Return value

In hosting mode, a successful deletion returns nothing. A failed deletion returns an exception.

In standard mode, a value is returned as follows:

Parameter

Type

Required

Description

result

object

Yes

Returns lists of successful and failed results: { successArr: [], errorArr: [] }

successArr (successful results)

If a file is deleted, the result in successArr is undefined. If a folder is deleted, the returned result contains the following fields.

Parameter

Type

Required

Description

async_task_id

string

Yes

The asynchronous task ID.

domain_id

string

Yes

Domain ID

drive_id

string

Yes

The disk ID.

share_id

string

The share ID. Valid in hosting mode.

file_id

string

(Required in standard mode)

The ID of the file or folder that was successfully deleted.

file_path

string

(Required in hosting mode)

The paths of files or folders whose deletion succeeded or failed.

errorArr (failed results)

If the operation fails, the information for the corresponding input file is returned.

Parameter

Type

Required

Description

share_id

string

The share ID. Valid in hosting mode.

drive_id

string

(Required in standard mode)

The disk ID.

file_id

string

(Required in standard mode)

The ID of the file or folder that failed to be deleted.

file_path

string

(Required in hosting mode)

The path of the file or folder that failed to be deleted.

copyFiles method

Note

Supported in standard and hosting modes.

This method copies a file or folder.

const result = await client.copyFiles(params, config, options)

Examples:

Copy multiple files

const {items=[]} = await client.listFiles(req)
                                          
// You can pass an array of fileItem objects directly:              
await client.copyFiles(items, {to_parent_file_id, to_drive_id})

When copying a single file, you can also rename it.

await client.copyFiles(item, { new_name: 'new file name', ... })

Cancel the copy operation

let stopFlag=false

// Cancel method
function cancel(){
  stopFlag=true
}

await client.copyFiles(items, {
  getStopFlag()=>{
    return stopFlag
  } 
})

Parameters

Parameter

Type

Required

Description

params

IFileItemKey[]

Yes

A list of files to copy. For information about the items, see the IFileKey type.

config

ICopyFilesConfig

Yes

Configuration for copying files.

options

AxiosRequestConfig

No

Other configuration items

IFileItemKey

Parameter

Type

Required

Description

drive_id

string

The disk ID. `drive_id` and `share_id` are mutually exclusive. You must specify one.

share_id

string

The share ID. Valid in hosting mode. `drive_id` and `share_id` are mutually exclusive. You must specify one.

file_id

string

(Required in standard mode)

The file or folder ID.

file_path

string

(Required in hosting mode)

The file or folder path.

parent_file_id

string

(Required in standard mode)

The parent folder ID.

parent_file_path

string

(Required in hosting mode)

The parent folder path.

ICopyFilesConfig

Parameter

Type

Required

Description

to_parent_file_path

string

(Required in hosting mode)

The path of the destination folder.

to_parent_file_id

string

(Required in standard mode)

The ID of the destination folder.

to_drive_id

string

(`to_drive_id` and `to_share_id` are mutually exclusive. You must specify one.)

The ID of the destination disk. Cross-disk copying is supported.

to_share_id

string

(`to_drive_id` and `to_share_id` are mutually exclusive. You must specify one.)

The ID of the destination shared directory. (Supported in hosting mode only).

new_name

string

For a single file, you can specify a new name.

onProgress

(count,totoal)=>{}

A callback for progress updates. It has two parameters: (count, total).

getStopFlag

()=>boolean

A method to pause the operation. Return true to pause. Return false to continue.

Returns

Parameter

Type

Required

Description

result

ICopyFileRes[]

Yes

A list of operation results.

ICopyFileRes

Parameter

Type

Required

Description

async_task_id

string

The asynchronous task ID. This is returned for folders only.

domain_id

string

Domain ID.

drive_id

string

(`drive_id` and `share_id` are mutually exclusive. You must specify one.)

The disk ID. `drive_id` and `share_id` are mutually exclusive.

share_id

string

(`drive_id` and `share_id` are mutually exclusive. You must specify one.)

The share ID. Supported in hosting mode. `drive_id` and `share_id` are mutually exclusive.

file_id

string

(Required in standard mode)

The file ID.

file_path

string

(Required in hosting mode)

File path

moveFiles method

Note

Supported in standard and hosting modes

This method moves a file or folder.

const result = await client.moveFiles(params, config, options)

Examples:

Move multiple files.

const {items=[]} = await client.moveFiles(...)
                                          
// You can pass an array of fileItem objects directly:                                    
await client.moveFiles(items, {to_parent_file_id, to_drive_id })

When moving a single file, you can also rename it.

await client.moveFiles(item, { new_name: 'new_file_name', ... })

You can cancel the copy operation during the shift procedure.

let stopFlag=false

// Cancel method
function cancel(){
  stopFlag=true
}

await client.moveFiles(items, {
  getStopFlag()=>{
    return stopFlag
  } 
})

Parameters

Parameter

Type

Required

Description

params

IFileItemKey[]

Yes

A list of files to move. For information about the items, see the IFileKey type.

config

ICopyFilesConfig

Yes

The configuration for moving files. For more information, see the description for the copyFiles method.

options

AxiosRequestConfig

No

Other configuration items

Return value

Parameter

Type

Required

Description

result

ICopyFileRes[]

Yes

A list of move results. For more information, see the return value of the copyFiles method.

getAsyncTask method

Note

Supported in standard and hosting modes.

This method retrieves the progress of a task.

const result = await client.getAsyncTask(async_task_id, options)

Parameters

Parameter

Type

Required

Description

async_task_id

string

Yes

The task ID.

options

AxiosRequestConfig

No

Other configuration items

Return value

Parameter

Type

Required

Description

result

object

Yes

The returned result. For more information, see the description of IAsyncTaskRes.

IAsyncTaskRes

Parameter

Type

Required

Description

async_task_id

string

Yes

The asynchronous task ID.

state

string

Yes

The status. Valid values: Failed | Success | Finished | Running

message

string

No

Message prompt

err_code

number

No

The information returned when the status is Failed.

url

string

No

The download URL returned after the archiveFile API successfully completes the packaging task.

pollingAsyncTask method

Note

Supported in standard and hosting modes.

This method polls for task progress until a final result is obtained.

const result = await client.getAsyncTask(async_task_id, ttl_ms options)

Parameters

Parameter

Type

Required

Description

async_task_id

string

Yes

The task ID.

ttl_ms

number

The polling interval in milliseconds. Default: 5000.

options

AxiosRequestConfig

Other configuration items

Return value

Parameter

Type

Required

Description

result

IAsyncTaskRes

Yes

The returned result.