全部產品
Search
文件中心

Drive and Photo Service:快速開始

更新時間:Dec 22, 2025

aliyun-pds-js-sdk 是PDS官方的推出的js sdk,提供PDS資源的基本操作方法,開發人員可以很方便的開發PDS網盤應用。除了上傳,下載,複製,移動,刪除等檔案基本操作外,還提供了Drive,Share,Group等資源的基本操作,同時支援瀏覽器和Node.js(electron或node服務)端。

github 開源地址: https://github.com/aliyun/aliyun-pds-js-sdk

重要
注意:從 1.0.0 開始,不再支援 HostingMode(託管模式)相關功能。
說明

node版本依賴:>=16.15.0

PDS資源說明

  1. Domain下的資源:

Domain/
  |-- Group                # 分組或團隊
  |-- User                 # 使用者
  |-- Account              # 帳號
  |-- Drive                # 雲端硬碟(網盤)
  |-- ShareLink            # 分享連結 
  |-- File                 # 檔案相關(新版共用許可權,資源回收筒)
  1. 一個 User 綁定多個 Account,一個Account 即一種登入方式,如:DingTalk登入。

  2. Group 下可以嵌套 Group 或者 User (通過 Membership)。

Group/
  |-- Group
  |-- User
  1. DriveOwner 可以為一個 Group 或者 User

  1. File 必屬於一個 Drive

Drive/          # 雲端硬碟
  |-- File

安裝

執行以下命令安裝:

npm i -S aliyun-pds-js-sdk

注意:請先確保已經安裝 Node.js >= 16.15.0。

引入

(1) 在 Vue 或 React 專案中使用

import {PDSClient} from 'aliyun-pds-js-sdk/browser' 

(2) 在 Node.js 中使用

const { PDSClient } = require('aliyun-pds-js-sdk')

(3) 在瀏覽器中以 script 標籤引入

npm 安裝後,在 node_modules/aliyun-pds-js-sdk/dist/browser/ 目錄下,有打包好的 aliyun-pds-js-sdk.umd.cjs 檔案,可以複製到你自己的靜態服務或CDN上,然後以 script 標籤引入。

<script src="/path/to/dist/browser/aliyun-pds-js-sdk.umd.cjs"></script>
const { PDSClient } = window.PDS_SDK

調用舉例

PDS API 的功能都整合在 PDSClient 類執行個體方法上,使用時只需 new 一個 PDSClient 執行個體,即可通過該執行個體的方法來調用 PDS 的各種 API。

const domain_id = "您的domainID" // 如:bj123
const config = {
   token_info: {...},
   api_endpoint: `https://${domain_id}.api.aliyunpds.com`,
}

const pds = new PDSClient(config)

let { items=[], next_marker } = await pds.listDrives({ limit:10 })
  • 關於構造參數 config 詳解,請看這裡:PDSClient類。