Share links

Updated at:

Manage share links using the PDS JavaScript SDK, including creating, canceling, and querying shares.

Note

The options parameter of the IPDSRequestConfig type is encapsulated based on the request config options of axios. For more information, see AxiosRequestConfig.

createShareLink method

Creates a share link for one or more files.

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

Example

await client.createShareLink({
  description: 'test',
  drive_id: '1060',
  expiration: '2021-12-08T15:59:59.999Z',
  file_id_list: ['61a49e39d687d40967164cf98ef65ab5bb554f53'],
  share_pwd: '831956',
})

Request parameters

Parameter

Type

Required

Description

params

ICreateShareLinReq

Yes

The parameters used to create a share link.

options

IPDSRequestConfig

Additional request parameters.

ICreateShareLinReq

Parameter

Type

Required

Description

description

string

The description of the share link.

drive_id

string

Yes

The drive ID.

share_pwd

string

The access code. Maximum 64 characters. Leave blank to share without an access code.

file_id_list

string[]

Yes

Applies in standard mode. A list of file or folder IDs to share. Maximum 100 entries.

file_path_list

string[]

Yes

Applies in hosting mode. Use either file_id_list or file_path_list, not both.

expiration

string

Yes

The expiration time of the share link in RFC 3339 format.

Example: 2020-06-28T11:33:00.000+08:00.

Leave blank for a permanently valid link.

Response parameters

Parameter

Type

Required

Description

result

IShareLinkItem

Yes

The details of the created share link.

cancelShareLink method

Cancels an existing share.

await client.cancelShareLink(params, options)

Example

await client.cancelShareLink({
  share_id: 'YgHgBeXGZWr'
})

Request parameters

Parameter

Type

Required

Description

params

Object

Yes

The parameters used to cancel a share.

options

IPDSRequestConfig

Additional request parameters.

params

Parameter

Type

Required

Description

share_id

string

Yes

The share ID.

Response parameters

No response parameters are returned.

listShareLinks method

Retrieves a list of shares.

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

Example

const {items=[], next_marker} = await client.listShareLinks({
  creator: 'user_id',
  marker: '',
  limit: 100,
})

Request parameters

Parameter

Type

Required

Description

params

Object

Yes

The parameters used to query shares.

options

IPDSRequestConfig

Additional request parameters.

params

Parameter

Type

Required

Description

limit

number

The maximum number of entries to return. Valid values: 1–100. Default value: 100.

marker

string

The pagination token for the start of the query.

creator

string

The user ID of the share creator. Behavior depends on whether the caller is an administrator:

As an administrator: omit to return shares from all users, or specify a user ID to return that user's shares.

As a regular user: omit to return your own shares. Specifying another user's ID returns error code 403.

Response parameters

Parameter

Type

Required

Description

result

IListRes<IShareLinkItem>

Yes

The returned result.

IListRes

Parameter

Type

Required

Description

items

IShareLinkItem[]

Yes

The list of share link items.

next_marker

string

The pagination token to use in the next request.

IShareLinkItem

Parameter

Type

Description

share_id

string

The share ID.

share_pwd

string

The access code. Returns an empty string when no access code is set.

share_msg

string

The share password.

share_url

string

The share link URL.

share_policy

'url' | 'msg'

The share policy. Valid values:

url: shares via a URL.

msg: shares via a password.

description

string

The description of the share link.

share_name

string

The name of the share.

download_count

number

The number of times the shared files have been downloaded.

preview_count

number

The number of times the shared files have been previewed.

save_count

number

The number of times the shared files have been saved.

drive_id

string

The drive ID.

share_pwd

string

The access code. Maximum 64 characters. Leave blank when no access code is required.

file_id_list

string[]

Returned in standard mode.

file_path_list

string[]

Returned in hosting mode.

expiration

Date

The expiration time of the share link in RFC 3339 format.

Example: 2020-06-28T11:33:00.000+08:00.

Empty when the share link is permanently valid.

expired

boolean

Indicates whether the share link has expired.

status

'enabled' | 'disabled'

The status of the share.

creator

string

The user ID of the share creator.

created_at

string

The time when the share was created.

updated_at

string

The time when the share was last updated.

getShareLinkByAnonymous method

Retrieves share information anonymously without an access token.

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

Example

const domain_id = 'Your domain ID'
const client = new PDSClient({
  api_endpoint: `https://${domain_id}.api.aliyunpds.com`
})
let info = client.getShareLinkByAnonymous({
  share_id: 'xxxxxx'
})

Request parameters

Parameter

Type

Required

Description

params

Object

Yes

The parameters used to query share information.

options

IPDSRequestConfig

Additional request parameters.

params

Parameter

Type

Required

Description

share_id

string

Yes

The share ID.

Response parameters

Parameter

Type

Required

Description

result

IAnonymousShareLinkItem

Yes

The returned result.

IAnonymousShareLinkItem

Parameter

Type

Required

Description

avatar

string

Yes

The profile picture of the user who shared the files.

creator_id

string

Yes

The user ID of the share creator.

creator_name

string

Yes

The nickname of the share creator.

creator_phone

string

The mobile number of the share creator.

disable_download

boolean

Indicates whether downloading the shared files is disabled.

disable_preview

boolean

Indicates whether previewing the shared files is disabled.

disable_save

boolean

Indicates whether saving the shared files is disabled.

enable_upload

boolean

Indicates whether uploading files to the share is enabled.

expiration

Date

The time when the share link expires.

preview_limit

number

The maximum number of times the shared files can be previewed.

require_login

boolean

Indicates whether a logon is required to view the shared files.

save_download_limit

number

The maximum number of times the shared files can be saved or downloaded.

share_name

string

The name of the share link.

updated_at

string

The time when the share link was last updated.

getShareToken method

Retrieves a share token anonymously without an access token.

Note

A share token is a temporary token for calling specific API operations such as listFiles, without requiring an access token. This lets users preview the shared files without logging on to the client.

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

Example

const domain_id = 'Your domain ID'
const client = new PDSClient({
  api_endpoint: `https://${domain_id}.api.aliyunpds.com`
})

try {
 
  let info = client.getShareToken({
    share_id: 'xxxxxx',
    // share_pwd: 'Access code' // If an access code is specified, enter the access code.
  })

}catch(e){
  // If an access code is required but no access code is specified, an error is reported.
  if (e.code == 'InvalidResource.SharePwd'){
    // An access code is required. 
  }
}

Request parameters

Parameter

Type

Required

Description

params

Object

Yes

The parameters used to retrieve a share token.

options

IPDSRequestConfig

Additional request parameters.

params

Parameter

Type

Required

Description

share_id

string

Yes

The share ID.

share_pwd

string

The access code.

Response parameters

Parameter

Type

Required

Description

result

IShareToken

Yes

The returned result.

IShareToken

Parameter

Type

Required

Description

share_token

string

Yes

The share token.

expire_time

string

Yes

The time when the share token expires.

expires_in

string

Yes

The validity period of the share token, in seconds.

Use a share token

The following example uses a share token to list shared files.

const share_token = 'The share token that you queried'
const share_id = 'Your share ID'
const domain_id = 'Your domain ID'

const client = new PDSClient({
  api_endpoint: `https://${domain_id}.api.aliyunpds.com`,
  share_token,
})

let {items=[], next_marker} = client.listFiles({ 
  share_id, 
  parent_file_id: 'root'
},
/*
{
  headers: {
    'x-share-token': share_token
  }
} */
)