Getting Started

Updated at:

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_info object — 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 config constructor parameter, see the PDSClient class.

PDS resource overview

  1. 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)
  1. A Group can nest another Group or a User using a Membership.

    Group/
      |-- Group
      |-- User
  2. The Owner of a Drive can be a Group or a User.

  3. The Owner of a Share can be a User. Share is supported only in hosting mode.

  4. A File must belong to a Drive or a Share. Share is supported only in hosting mode.

    Drive/          # Disk
      |-- File
    
    Share/          # Shared folder (supported only in hosting mode)
      |-- File
  5. The File primary 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