Getting Started
The aliyun-pds-js-sdk is the official JavaScript software development kit (SDK) for PDS. It supports file operations including upload, download, copy, move, and delete, along with management of Drive, Share, and Group resources. The SDK runs in browsers and Node.js environments, including Electron and Node.js services.
GitHub repository: https://github.com/aliyun/aliyun-pds-js-sdk/tree/0.2.11.
Prerequisites
Before you begin, ensure that you have:
Node.js installed
A PDS domain ID (for example,
bj123)A valid
token_infoobject — obtain this by authenticating with the PDS auth endpoint for your domain
Install the SDK
Run the following command to install the SDK:
npm i -S aliyun-pds-js-sdk@0.2.11
Import in a Vue or React project
import {PDSClient} from 'aliyun-pds-js-sdk'
Import in Node.js
const { PDSClient } = require('aliyun-pds-js-sdk')
Import using a script tag in a browser
After installing the SDK with npm, find aliyun-pds-js-sdk.min.js in the node_modules/aliyun-pds-js-sdk/dist/ directory. Copy it to your static service or CDN, then import it with a script tag.
<script src="/path/to/aliyun-pds-js-sdk.min.js"></script>
const { PDSClient } = window.PDS_SDK
Make your first API call
The following example initializes a PDSClient instance and lists all drives in your domain. All PDS API features are available as methods on PDSClient.
import { PDSClient } from 'aliyun-pds-js-sdk'
const domain_id = "your_domain_id" // For example: bj123
const config = {
token_info: {...},
api_endpoint: `https://${domain_id}.api.aliyunpds.com`,
auth_endpoint: `https://${domain_id}.api.aliyunpds.com`,
}
const pds = new PDSClient(config)
let { items=[], next_marker } = await pds.listDrives({ limit:10 })
For details on the
configconstructor parameter, see the PDSClient class.
PDS resource overview
Resources within a
Domain:
Domain/
|-- Group & Membership # Group or team
|-- User # User
|-- Account # Account
|-- Drive # Disk (network disk)
|-- Share # Shared folder (deprecated in the latest version, use the sharing API in File instead)
|-- ShareLink # Share link
|-- File # File-related (new sharing permissions, recycle bin)
-
A
Groupcan nest anotherGroupor aUserusing aMembership.Group/ |-- Group |-- User The
Ownerof aDrivecan be aGroupor aUser.The
Ownerof aSharecan be aUser.Shareis supported only in hosting mode.-
A
Filemust belong to aDriveor aShare.Shareis supported only in hosting mode.Drive/ # Disk |-- File Share/ # Shared folder (supported only in hosting mode) |-- File -
The
Fileprimary key differs between standard mode (StandardMode) and hosting mode (HostingMode):* Standard mode: The key is file_id Drive/ # Disk |-- File (type=='folder', file_id="xxxxxxxx1") # Directory (folder) |-- File (type=='file', file_id="xxxxxxxx2") # File * Hosting mode: The key is file_path Drive|Share/ # Disk/Shared folder |-- File (type=='folder',file_path:'/abc/') # Directory (folder) |-- File (type=='file',file_path:'/abc/1.jpg') # File