全部產品
Search
文件中心

Drive and Photo Service:檔案操作

更新時間:Dec 23, 2025

提供檔案相關的操作方法,包括檔案增刪改查,複製,移動等。以下所有方法中的 options 參數是額外請求配置,詳見 AxiosRequestConfig

listFiles 方法

說明

標準模式和託管模式都支援

列舉指定目錄下的檔案或檔案夾。

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

舉例

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

參數說明

欄位

類型

必選

說明

params

IListFileReq

查詢參數

options

AxiosRequestConfig

其它配置項

IListFileReq

欄位

類型

必選

說明

drive_id

string

(標準模式必選)

雲端硬碟ID。drive_id和share_id互斥必選一個。

share_id

string

(託管模式drive_id和share_id互斥必選一個)

共用ID(託管模式支援)。drive_id和share_id互斥必選一個。

parent_file_id

string

(標準模式必選)

上級檔案目錄ID

parent_file_path

string

(託管模式必選)

上級檔案路徑

fields

string

返迴文件欄位,返回全部欄位傳 "*"。不傳則只返回基本欄位。預設: 不傳。

url_expire_sec

number

URL有效時間

video_thumbnail_process

string

影片縮圖處理運算式。 請參考 圖片處理

image_thumbnail_process

string

圖片縮圖處理運算式。 請參考 圖片處理

image_url_process

string

圖片URL處理運算式。 請參考 圖片處理

limit

number

返回的數量限制

marker

string

分頁標記

order_by

string

排序欄位

order_direction

string

可選值 'DESC' | 'ASC'

starred

boolean

是否收藏

category

string

類別

status

string

狀態

type

string

檔案類型, 可選 'file' | 'folder'

IFileItem(HostingMode模式傳回值)

欄位

類型

必選

說明

content_type

string

內容類型

domain_id

string

domain ID

download_url

string

下載URL, 僅檔案類型返回

drive_id

string

雲端硬碟ID

file_extension

string

副檔名

file_path

string

檔案路徑

name

string

名稱

parent_file_path

string

上級目錄

size

number

檔案大小,單位Byte

status

string

可選值 'available' | 'uploading'

share_id

string

共用ID

thumbnail

string

縮圖URL。

type

string

檔案類型,可選值

updated_at

Date

更新時間

url

string

檔案URL

IFileItem(StandardMode模式傳回值)

欄位

類型

必選

說明

action_list

array

許可權列表

category

string

檔案類型, 取值:doc | image | video | audio | zip | others

content_hash

string

檔案標識

content_hash_name

string

使用的加密方式

content_type

string

內容類型

crc64_hash

string

crc計算的hash值

created_at

Date

建立時間

creator_id

string

建立人ID

creator_name

string

建立人名稱

creator_type

string

建立人類型,取值:'group' | 'user'

domain_id

string

domain ID

download_url

string

下載URL,檔案類型返回

drive_id

string

雲端硬碟ID

description

string

描述資訊

encrypt_mode

string

加密模式

file_extension

string

副檔名, 如: .txt

file_id

string

檔案夾ID

hidden

boolean

是否隱藏

last_modifier_id

string

最後修改人ID

last_modifier_name

string

最後修改人名稱

last_modifier_type

string

修改人類型,取值:'group' | 'user'

labels

string

標籤

location

string

位置

mime_extension

string

媒體類型副檔名

mime_type

string

媒體類型

meta

string

雲資訊

name

string

檔案夾名稱

parent_file_id

string

上級目錄ID

punish_flag

number

錯誤數量

revision_id

string

修訂版本

rapid_upload

boolean

是否秒傳

size

number

檔案大小,單位Byte

starred

boolean

是否收藏

status

string

可選值 'available' | 'uploading'

streams_upload_info

流上傳資訊

thumbnail

string

檔案才有

type

string

檔案類型,可選值 'file' | 'folder'

trashed

boolean

是否已被移到資源回收筒裡

updated_at

Date

更新時間

user_meta

string

upload_id

string

上傳ID

url

string

原檔案URL

  • download_urlurl 的區別:download_url 會增加

    Content-Disposition: attachment; filename="filename"

    訊息頭,瀏覽器會直接下載。URL沒有這個訊息頭,有些檔案瀏覽器會直接開啟,比如瀏覽器支援直接開啟的圖片,mp4,pdf等。

  • 關於 thumbnail, 圖片,視頻等才有縮圖。

searchFiles 方法

重要

僅標準模式支援

警告

託管模式不支援

根據條件搜尋檔案。

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

參數說明

欄位

類型

必選

說明

params

object

搜尋相關參數,請查看 ISearchFileReq

options

AxiosRequestConfig

其它配置項

isRecycleBin

boolean

資源回收筒搜尋傳 true, 其它傳 false, 預設為false

ISearchFileReq

欄位

類型

必選

說明

limit

number

返回的數量限制。

query

string

篩選條件陳述式,具體用法請看檔案搜尋

drive_id

string

雲端硬碟ID

fields

string

返迴文件欄位,返回全部欄位傳 "*"。不傳則只返回基本欄位。預設: 不傳。

order_by

string

排序欄位

marker

string

分頁標記

url_expire_sec

number

URL 有效時間。預設2小時

image_thumbnail_process

string

圖片縮圖處理運算式。請參考 圖片處理

image_url_process

string

圖片URL 處理運算式。請參考 圖片處理

video_thumbnail_process

string

影片縮圖處理運算式。請參考 圖片處理

傳回值

欄位

類型

必選

說明

result

IListRes

返回結果

IListRes

欄位

類型

必選

說明

items

array

檔案清單,具體項欄位請參考 listFiles 方法中的 IFileItem 類型 StandardMode模式傳回值

next_marker

string

分頁標記

getFile 方法

說明

標準模式和託管模式都支援

根據檔案ID查詢檔案資訊。

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

參數說明

欄位

類型

必選

說明

params

object

查詢參數,查看 IGetFileReq 類型

options

AxiosRequestConfig

其它配置項

IGetFileReq

欄位

類型

必選

說明

drive_id

string

(標準模式必選)

雲端硬碟ID。drive_id和share_id互斥必選其一。

share_id

string

(託管模式drive_id和share_id互斥必選一個)

共用ID(託管模式支援)。drive_id和share_id互斥必選其一。

file_id

string

(標準模式必選)

檔案ID

file_path

string

(託管模式必選)

檔案路徑

fields

string

返迴文件欄位,返回全部欄位傳 "*"。不傳則只返回基本欄位。預設: 不傳。

url_expire_sec

number

返回的各個 URL 簽名的有效時間。

video_thumbnail_process

string

影片縮圖處理運算式。 請參考 圖片處理

image_thumbnail_process

string

圖片縮圖處理運算式。 請參考 圖片處理

image_url_process

string

圖片URL處理運算式。 請參考 圖片處理

傳回值

欄位

類型

必選

說明

result

object

返回結果,具體請查看 IFileItem 類型

getFileDownloadUrl

新增於:v0.1.3

說明

標準模式和託管模式都支援

擷取檔案的 download_url, 在瀏覽器中開啟 download_url 可以直接下載檔案。

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

舉例

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

參數說明:

欄位

類型

必選

說明

params

object

查詢參數,查看 IGetFileDownloadUrlReq 類型

options

AxiosRequestConfig

其它配置項

IGetFileDownloadUrlReq

欄位

類型

必選

說明

drive_id

string

(標準模式必選)

雲端硬碟ID。drive_id和share_id互斥必選其一。

share_id

string

(託管模式drive_id和share_id互斥必選一個)

共用ID(託管模式支援)。drive_id和share_id互斥必選其一。

file_id

string

(標準模式必選)

檔案ID

file_path

string

(託管模式必選)

檔案路徑

fields

string

返迴文件欄位,返回全部欄位傳 "*"。不傳則只返回基本欄位。預設: 不傳。

返回

欄位

類型

必選

說明

result

object

返回結果,具體請查看 IGetFileDownloadUrlRes 類型

IGetFileDownloadUrlRes

欄位

類型

必選

說明

expiration

string

到期時間。

method

string

適用的HTTP方法,一般為 GET。

url

string

檔案下載 URL。

size

number

檔案大小,單位Byte。

saveFileContent 方法

說明

標準模式和託管模式都支援

儲存內容到檔案, 或者建立檔案。

對於託管模式,同名檔案會覆蓋。

對於標準模式,傳入相同檔案ID會覆蓋,不傳檔案ID,會被認為是新檔案,將根據 check_name_mode 參數執行相應的策略。check_name_mode 預設是 'refuse'。

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

舉例

建立空檔案

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

修改已有檔案的內容

await client.saveFileContent(fileItem, '修改的內容')

參數說明

欄位

類型

必選

說明

params

IGetFileReq

檔案資訊,查看 IGetFileReq 類型

content

string

檔案內容,預設為空白 ''

config

ISaveFileConfig

其他配置

ISaveFileConfig

欄位

類型

必選

說明

check_name_mode

boolean

(標準模式有效)同名策略配置,取值範圍:

auto_rename: 檔案名稱後面增加隨機數。

refuse: 拋出 codeAlreadyExists 的異常

ignore: 允許同名。

預設 refuse。

如果第一個參數含有 file_id 欄位, 則此欄位失效。

ignore_rapid

boolean

(標準模式有效,主要用來測試)強制不秒傳,預設false。

傳回值

欄位

類型

必選

說明

result

object

返回結果,具體請查看 IFileItem 類型

getFileContent 方法

說明

標準模式和託管模式都支援

擷取檔案內容(一般用來讀取文字檔內容)。

注意,此方法擷取檔案內容直接賦值給變數,如果檔案太大(太佔用記憶體)不建議使用此方法。

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

參數說明

欄位

類型

必選

說明

params

IGetFileReq

請求參數

options

AxiosRequestConfig

其他請求參數

  • 傳回值中的 content 欄位,和 options.responseType 相關。預設responseType為 arraybuffer。返回的content是 Buffer(for node.js)| ArrayBuffer(for 瀏覽器)。

  • 如果確定檔案內容是文字檔,options.responseType 應該設定為 text,這樣返回的 content就是個字串。

傳回值

欄位

類型

必選

說明

result

object

返回結果

result

欄位

類型

必選

說明

headers

object

相應頭資訊

content

Buffer | string | ...

內容資訊,可能為空白。 根據 responseType 的設定返回不同格式。詳細情況請參考axios的responseType說明。

size

number

檔案大小,單位Byte

type

string

檔案ID

updated_at

string

更新時間

status

string

狀態

renameFile 方法

說明

標準模式和託管模式都支援

檔案/檔案夾重新命名

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

舉例

標準模式:

await client.renameFile({
  drive_id: "1",
  file_id: 'xxxxxx',
}, '新的名稱.txt')

託管模式:

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

參數說明

欄位

類型

必選

說明

fileItem

IFileItem

要重新命名的檔案資訊,查看 IFileItem 類型

newName

string

新名稱

check_name_mode

string

(標準模式有效)同名策略配置,取值範圍:

auto_rename: 檔案名稱後面增加隨機數。

refuse: 拋出 codeAlreadyExists 的異常

ignore: 允許同名。

預設 refuse。

如果第一個參數含有 file_id 欄位, 則此欄位失效。

傳回值

欄位

類型

必選

說明

result

object

返回結果,查看 IFileItem 類型

  • 在託管模式下,遇到同名檔案,會拋 codeAlreadyExists 的異常。

updateFile 方法

重要

標準模式支援

警告

託管模式不支援

修改檔案/檔案夾資訊。

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

參數說明

欄位

類型

必選

說明

params

object

要更新的檔案資訊 ,欄位請查看 IUpdateFileReq

options

AxiosRequestConfig

其它配置項

IUpdateFileReq

欄位

類型

必選

說明

drive_id

string

雲端硬碟ID。drive_id 和 share_id 互斥必選一個

file_id

string

檔案ID

check_name_mode

string

同名策略配置,取值範圍:

auto_rename: 檔案名稱後面增加隨機數。

refuse: 拋出 codeAlreadyExists 的異常

ignore: 允許同名。

parent_file_id

string

上級目錄ID

custom_index_key

string

自訂的key

description

string

描述

encrypt_mode

string

加密模式

hidden

boolean

是否隱藏

labels

array

標籤

meta

string

name

string

名稱

starred

boolean

是否收藏

user_meta

string

傳回值

欄位

類型

必選

說明

result

object

返回更新之後的資訊,具體項欄位請參考 listFiles 方法中的 IFileItem 類型

getFileByPath 方法

重要

標準模式支援

警告

託管模式不支援

根據路徑擷取檔案或檔案夾資訊。

比如: 根據 /a/b/c ,擷取對應的檔案Item資訊。

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

參數說明

欄位

類型

必選

說明

params

IGetFileByPathReq

參數

options

AxiosRequestConfig

其它配置項

IGetFileByPathReq

欄位

類型

必選

說明

drive_id

string

drive ID。

file_path

string

檔案夾路徑,樣式如: ‘/a/b/c’ 。

fields

string

檔案類型,全部為 *

url_expire_sec

number

URL有效時間

video_thumbnail_process

string

影片縮圖處理運算式。 請參考 圖片處理

image_thumbnail_process

string

圖片縮圖處理運算式。 請參考 圖片處理

image_url_process

string

圖片URL處理運算式。 請參考 圖片處理

傳回值

欄位

類型

必選

說明

result

object

返回結果,具體請查看 IFileItem 類型

getBreadcrumbFolderList 方法

說明

v0.1.7 加入

重要

標準模式支援

警告

託管模式不支援

擷取多級麵包屑目錄資訊:從目前的目錄遞迴向上尋找所有目錄資訊(調用getFile介面)。

返回的數組不包含root目錄。

異常情況

* 1. 遇到沒有許可權(403)的目錄,將截止。返回的數組包含一個 is_forbidden==true 的目錄資訊。

* 2. 其他異常直接拋出報錯。

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

舉例

// 假設有目錄:/a/b/c/
// 目錄 c 的 file_id 為 “620cb4363a20321aa66a495ca063ac2679a8f726”

const arr = await client.getBreadcrumbFoldderList({
  drive_id,
  file_id,
})
// 返回多級麵包屑目錄資訊:[{file_id:'a的目錄ID', name:'a'},{file_id:'b的目錄ID', name:'b'}]

參數說明

欄位

類型

必選

說明

params

IGetBreadcrumbReq

參數

options

AxiosRequestConfig

其它配置項

IGetBreadcrumbReq

欄位

類型

必選

說明

drive_id

string

(drive_id 和 share_id 必選一個)

雲端硬碟 ID 。drive_id 和 share_id 互斥,必選一個。

share_id

string

(drive_id 和 share_id 必選一個)

分享ID。drive_id 和 share_id 互斥,必選一個。

file_id

string

目前的目錄 ID

end_parent_id

string

截止尋找的父目錄ID。預設: root

返回

欄位

類型

必選

說明

result

IParentFolderNameId[]

返回結果。

IParentFolderNameId

欄位

類型

必選

說明

file_id

string

目錄的檔案ID

name

string

目錄名稱

is_forbidden

boolean

遇到沒有許可權查詢的目錄時為true。

getBreadcrumbFolders 方法

警告

(不推薦使用此方法)請使用 getBreadcrumbFolderList 方法替代

重要

標準模式支援

警告

託管模式不支援

擷取多級麵包屑目錄資訊:從目前的目錄遞迴向上尋找所有目錄資訊(調用getFile介面)。

返回的數組不包含root目錄。

異常情況

* 1. 遇到沒有許可權(403)的目錄,將截止。返回的數組包含一個 is_forbidden==true 的目錄資訊。

* 2. 其他異常直接拋出報錯。

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

參數說明

欄位

類型

必選

說明

drive_id

string

當前雲端硬碟 ID

file_id

string

目前的目錄 ID

end_parent_id

string

截止尋找的父目錄ID。預設: root

傳回值

欄位

類型

必選

說明

result

IParentFolderNameId[]

返回結果。

IParentFolderNameId

欄位

類型

必選

說明

file_id

string

目錄的檔案ID

name

string

目錄名稱

is_forbidden

boolean

遇到沒有許可權查詢的目錄時為true。

createFolder 方法

說明

標準模式和託管模式都支援

建立目錄(檔案夾)

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

舉例:

await client.createFolder({
  name: '建立檔案夾',  
  drive_id: '1',
  parent_file_id: 'root',
  // check_name_mode:'auto_rename'
})

參數說明

欄位

類型

必選

說明

params

ICreateFolderReq

查看 ICreateFolderReq 類型

options

AxiosRequestConfig

其它配置項

ICreateFolderReq

欄位

類型

必選

說明

check_name_mode

string

(標準模式有效)同名策略配置,取值範圍:

auto_rename: 檔案名稱後面增加隨機數。

refuse: 拋出 codeAlreadyExists 的異常

ignore: 允許同名。

預設 refuse。

drive_id

string

(標準模式必選)

雲端硬碟ID。drive_id 和 share_id 互斥必選一個。

share_id

string

(託管模式有效, drive_id 和 share_id 互斥必選一個)

共用ID(託管模式有效)。drive_id 和 share_id 互斥必選一個。

name

string

目錄名稱

parent_file_id

string

(標準模式必選)

上級檔案ID,根路徑傳 root

parent_file_path

string

(託管模式必選)

上級檔案路徑

傳回值

欄位

類型

必選

說明

result

ICreateFolderRes

返回結果

ICreateFolderRes

欄位

類型

必選

說明

domain_id

string

domain ID

drive_id

string

雲端硬碟ID

share_id

string

共用ID(託管模式有效)

encrypt_mode

string

加密模式(標準模式有效)

file_id

string

(標準模式必選)

檔案ID

file_path

string

(託管模式必選)

檔案路徑

file_name

string

檔案名稱

parent_file_id

string

(標準模式必選)

上級檔案ID,根路徑傳 root(標準模式有效)

type

string

檔案類型,可選值 'file' | 'folder',

範例:

{
  "parent_file_id": "root",
  "type": "folder",
  "file_id": "61ba1892abbe9f56bb7342c4beee82156e68dd67",
  "domain_id": "daily123",
  "drive_id": "1",
  "file_name": "建立檔案夾",
  "encrypt_mode": "none"
}
{
  "type":"folder",
  "file_path":"/建立檔案夾2/",
  "domain_id":"hz63",
  "drive_id":"4801"
}

createFolders 方法

說明

標準模式和託管模式都支援

如果遇到同名的情況,託管模式會直接覆蓋,標準模式根據 check_name_mode 策略執行。

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

參數說明

欄位

類型

必選

說明

folderNames

string[]

目錄名稱,比如要建立的目錄是 ‘a/b/c’, 傳入格式 ['a', 'b', 'c' ]

parentKey

IParentFileKey

建立多級檔案夾參數

config

ICreateFoldersConfig

可選配置參數

IParentFileKey

欄位

類型

必選

說明

drive_id

string

雲端硬碟ID

share_id

string

共用ID (託管模式有效)

parent_file_id

string

(標準模式必選)

上級目錄ID,根目錄為 root

parent_file_path

string

(託管模式必選)

上級目錄路徑,根目錄為 /

ICreateFoldersConfig

欄位

類型

必選

說明

check_name_mode

string

(標準模式有效)同名策略配置,取值範圍:

auto_rename: 檔案名稱後面增加隨機數。

refuse: 回調 onFolderRepeat

ignore: 允許同名。

預設 refuse。

create_folder_cache

Map<string, any>={}

緩衝目錄資訊的map。

onFolderRepeat

()=>boolean

(標準模式有效)發現路徑存在時的回調,返回 true 繼續,返回 false,會拋出codeAlreadyExists的錯誤

onFolderCreated

(fileItem)=>void

建立成功的回調

傳回值

欄位

類型

必選

說明

result

string

建立成功的路徑

deleteFile 方法

說明

標準模式和託管模式都支援

刪除指定檔案或者檔案夾。

await client.deleteFile(params, permanently, options)

參數說明

欄位

類型

必選

說明

params

IFileKey

要刪除的檔案資訊

permanently

boolean

是否永久刪除,false 表示暫時刪除,true 表示永久刪除, 預設 false (託管模式不支援暫時刪除)

options

AxiosRequestConfig

其它配置項

IFileKey

欄位

類型

必選

說明

share_id

string

(託管模式有效,drive_id 和 share_id 互斥必須選一個)

共用id,drive_id 和 share_id 互斥必須選一個

drive_id

string

(標準模式必選)

雲端硬碟id,drive_id 和 share_id 互斥必須選一個

file_id

string

(標準模式必選)

要刪除的檔案或檔案夾ID

file_path

string

(託管模式必選)

要刪除的檔案或檔案夾路徑

返回

如果是標準模式,返回以下欄位:

欄位

類型

必選

說明

async_task_id

string

(託管模式有效,drive_id 和 share_id 互斥必須選一個)

共用id,drive_id 和 share_id 互斥必須選一個

domain_id

string

(標準模式必選)

雲端硬碟id,drive_id 和 share_id 互斥必須選一個

file_id

string

(標準模式必選)

要刪除的檔案或檔案夾ID

如果是託管模式,無返回。

batchDeleteFiles 方法

說明

標準模式和託管模式都支援

大量刪除指定檔案或者檔案夾。

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

參數說明

欄位

類型

必選

說明

params

IFileKey[]

要刪除的檔案資訊列表,支援批量,其中每一項的欄位請參考 IBatchFileReq 的說明。(注意:只需傳入要刪除的檔案ID或目錄ID,該方法會自動遞迴目錄刪除下面的檔案。)

permanently

boolean

是否永久刪除,false 表示暫時刪除,true 表示永久刪除, 預設 false (託管模式不支援暫時刪除)

options

AxiosRequestConfig

其它配置項

傳回值

HostingMode 模式刪除成功沒有傳回值,刪除失敗返回異常資訊。

StandardMode 模式有傳回值,傳回值如下:

欄位

類型

必選

說明

result

object

返回刪除成功和失敗的結果清單 { successArr: [], errorArr: [] }

successArr 成功結果

如果刪除的是檔案,successArr 中的結果為 undefined,如果刪除的是檔案夾,返回的結果包含如下欄位。

欄位

類型

必選

說明

async_task_id

string

非同步任務ID

domain_id

string

domain ID

drive_id

string

雲端硬碟ID

share_id

string

共用ID(託管模式有效)

file_id

string

(標準模式必選)

刪除失敗成功的檔案或檔案夾ID

file_path

string

(託管模式必選)

刪除失敗成功的檔案或檔案夾路徑

errorArr 失敗結果

如果失敗了,則會將傳入的檔案資訊對應的返回。

欄位

類型

必選

說明

share_id

string

共用ID(託管模式有效)

drive_id

string

(標準模式必選)

雲端硬碟ID

file_id

string

(標準模式必選)

刪除失敗的檔案或檔案ID

file_path

string

(託管模式必選)

刪除失敗檔案或檔案夾路徑

copyFiles 方法

說明

標準模式和託管模式都支援

複製檔案或檔案夾。

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

舉例:

複製多個檔案

const {items=[]} = await client.listFiles(req)
                                          
// 可以直接傳入 fileItem 數組:              
await client.copyFiles(items, {to_parent_file_id, to_drive_id})

對於複製單個檔案,可以重新命名

await client.copyFiles(item, { new_name: '新檔案名稱', ... })

複製過程中取消複製

let stopFlag=false

// 取消方法
function cancel(){
  stopFlag=true
}

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

參數說明

欄位

類型

必選

說明

params

IFileItemKey[]

要複製的檔案清單,其中的項可查看 IFileKey 類型

config

ICopyFilesConfig

複製檔案相關配置

options

AxiosRequestConfig

其它配置項

IFileItemKey

欄位

類型

必選

說明

drive_id

string

雲端硬碟id。drive_id和share_id互斥必選一個。

share_id

string

共用id(託管模式有效)。drive_id和share_id互斥必選一個。

file_id

string

(標準模式必選)

檔案或檔案夾ID

file_path

string

(託管模式必選)

檔案或檔案夾路徑

parent_file_id

string

(標準模式必選)

上級檔案夾ID

parent_file_path

string

(託管模式必選)

上級檔案夾路徑

ICopyFilesConfig

欄位

類型

必選

說明

to_parent_file_path

string

(託管模式必選)

複製到該檔案夾下,檔案夾路徑

to_parent_file_id

string

(標準模式必選)

複製到該檔案夾下,檔案夾ID

to_drive_id

string

(to_drive_id和to_share_id互斥必選一個)

複製到目標雲端硬碟ID, 支援跨雲端硬碟複製。

to_share_id

string

(to_drive_id和to_share_id互斥必選一個)

複製到目標共用目錄ID(只支援託管模式)。

new_name

string

對於單個檔案,可以重新命名。

onProgress

(count,totoal)=>{}

進度的回調,有兩個參數 (count, total) 。

getStopFlag

()=>boolean

暫停方法。返回true則暫停。返回false則繼續。

返回

欄位

類型

必選

說明

result

ICopyFileRes[]

操作結果清單

ICopyFileRes

欄位

類型

必選

說明

async_task_id

string

非同步任務ID。 檔案夾才有。

domain_id

string

Domain ID。

drive_id

string

(drive_id 和 share_id 互斥必選一個)

雲端硬碟ID。drive_id 和 share_id 互斥。

share_id

string

(drive_id 和 share_id 互斥必選一個)

共用ID(託管模式支援)。drive_id 和 share_id 互斥。

file_id

string

(標準模式必選)

檔案ID

file_path

string

(託管模式必選)

檔案路徑

moveFiles 方法

說明

標準模式和託管模式都支援

移動檔案或檔案夾。

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

舉例:

移動多個檔案。

const {items=[]} = await client.moveFiles(...)
                                          
// 可以直接傳入 fileItem 數組:                                    
await client.moveFiles(items, {to_parent_file_id, to_drive_id })

對於移動單個檔案,可以重新命名。

await client.moveFiles(item, { new_name: '新檔案名稱', ... })

移動過程中取消複製。

let stopFlag=false

// 取消方法
function cancel(){
  stopFlag=true
}

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

參數說明

欄位

類型

必選

說明

params

IFileItemKey[]

要移動的檔案清單,其中的項可查看 IFileKey 類型

config

ICopyFilesConfig

移動檔案相關配置,請參考 copyFiles 方法的描述

options

AxiosRequestConfig

其它配置項

傳回值

欄位

類型

必選

說明

result

ICopyFileRes[]

移動結果清單。 請參考 copyFiles 方法的返回。

getAsyncTask 方法

說明

標準模式和託管模式都支援

擷取任務進度。

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

參數說明

欄位

類型

必選

說明

async_task_id

string

任務ID

options

AxiosRequestConfig

其它配置項

傳回值

欄位

類型

必選

說明

result

object

返回結果,具體請查看 IAsyncTaskRes 的說明

IAsyncTaskRes

欄位

類型

必選

說明

async_task_id

string

非同步任務ID

state

string

狀態, Failed | Success | Finished | Running

message

string

訊息提示

err_code

number

狀態為 Failed 時返回的資訊

url

string

archiveFile介面最終打包任務成功之後返回的下載地址

pollingAsyncTask 方法

說明

標準模式和託管模式都支援

輪詢擷取任務進度,直到擷取到最終結果。

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

參數說明

欄位

類型

必選

說明

async_task_id

string

任務ID

ttl_ms

number

輪訓間隔時間, 單位ms,預設: 5000

options

AxiosRequestConfig

其它配置項

傳回值

欄位

類型

必選

說明

result

IAsyncTaskRes

返回結果