In the following methods, the options parameter specifies additional request configurations. For more information, see AxiosRequestConfig.
createShareLink method
Supported in both standard mode and hosted mode.
Creates a share link.
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',
})Parameters
Field | Type | Required | Description |
params | ICreateShareLinReq | Yes | Share creation parameters. |
options | AxiosRequestConfig | Other configuration items. |
ICreateShareLinReq
Field | Type | Required | Description |
description | string | The description. | |
drive_id | string | Yes | The disk ID. |
share_pwd | string | The share password, 0 to 64 characters in length. A length of 0 indicates no password. | |
file_id_list | string[] | Yes | (Valid only in standard mode). A list of files or folders. Maximum: 100. |
file_path_list | string[] | Yes | (Valid only in hosted mode). You only need to pass either file_path_list or file_id_list. |
expiration | string | Yes | The expiration time in RFC 3339 format. For example: "2020-06-28T11:33:00.000+08:00" Permanent: "" |
Returns
Field | Type | Required | Description |
result | IShareLinkItem | Yes | The share link details. |
cancelShareLink method
Supported in both standard mode and hosted mode.
Cancels a share link.
await client.cancelShareLink(params, options)Example
await client.cancelShareLink({
share_id: 'YgHgBeXGZWr'
})Parameters
Field | Type | Required | Description |
params | Object | Yes | The cancel share parameters. |
options | AxiosRequestConfig | Other configuration items. |
params
Field | Type | Required | Description |
share_id | string | Yes | The share ID. |
Returns
None.
listShareLinks method
Supported in both standard mode and hosted mode.
Lists share links.
const result = await client.listShareLinks(params, options)Example
const {items=[], next_marker} = await client.listShareLinks({
creator: 'user_id',
marker: '',
limit: 100,
})Parameters
Field | Type | Required | Description |
params | Object | Yes | The list share parameters. |
options | AxiosRequestConfig | Other configuration items. |
params
Field | Type | Required | Description |
limit | number | The maximum number of entries to return. Range: [1-100]. Default: 100. | |
marker | string | The start marker for the query. | |
creator | string | For an administrator: 1. If you omit this parameter, the system queries shares from all users. 2. If you specify a user_id, the system queries shares from that user. For a regular user: 2.1 If no parameter is passed, the system retrieves information about the current user. 2. If you specify a user_id, it must be your own ID. Otherwise, a 403 error occurs. |
Returns
Field | Type | Required | Description |
result | IListRes<IShareLinkItem> | Yes | The result. |
IListRes
Field | Type | Required | Description |
items | IShareLinkItem[] | Yes | An array of IShareLinkItem objects. |
next_marker | string | The start marker for querying the next page. |
IShareLinkItem
Field | Type | Description |
share_id | string | The share ID. |
share_pwd | string | The share password. If no password was passed, this field returns an empty string, which indicates that no password is required. |
share_msg | string | The share security token. |
share_url | string | The share URL. |
share_policy | 'url' | 'msg' | The share policy. url: Share using a link. msg: Share using a security token. |
description | string | The description. |
share_name | string | The share name. |
download_count | number | The number of downloads. |
preview_count | number | The number of previews. |
save_count | number | The number of saves. |
drive_id | string | The disk ID. |
share_pwd | string | The share password, 0 to 64 characters in length. A length of 0 indicates no password. |
file_id_list | string[] | This field is returned in standard mode. |
file_path_list | string[] | This field is returned in hosted mode. |
expiration | Date | The expiration time in RFC 3339 format. For example: "2020-06-28T11:33:00.000+08:00" Never expires: "" |
expired | boolean | Indicates whether the link has expired. |
status | 'enabled' | 'disabled' | The share status. |
creator | string | The creator ID. |
created_at | Date | The creation time. |
updated_at | Date | The update time. |
getShareLinkByAnonymous method
Added in v0.1.3.
Anonymously retrieves share information without a 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'
})Parameters
Field | Type | Required | Description |
params | Object | Yes | The parameters. |
options | AxiosRequestConfig | Other configuration items. |
params
Field | Type | Required | Description |
share_id | string | Yes | The share ID. |
Returns
Field | Type | Required | Description |
result | IAnonymousShareLinkItem | Yes | The result. |
IAnonymousShareLinkItem
Field | Type | Required | Description |
avatar | string | Yes | The sharer's profile picture. |
creator_id | string | Yes | The creator's user ID. |
creator_name | string | Yes | The creator's nickname. |
creator_phone | string | The creator's phone number. | |
disable_download | boolean | Disables downloads. | |
disable_preview | boolean | Disables previews. | |
disable_save | boolean | Disables saves. | |
enable_upload | boolean | Enables uploads. | |
expiration | Date | The expiration time. | |
preview_limit | number | The preview count limit. | |
require_login | boolean | Requires logon to view. | |
save_download_limit | number | The save or download count limit. | |
share_name | string | The share link name. | |
updated_at | Date | The last modification time. |
getShareToken method
Added in v0.1.3.
Anonymously obtains a share token without an access token.
What is a share token (share_token)?
A share token is a temporary token. It can replace an access token to call certain APIs, such as listFiles. This allows users to access shared content without logging in.
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: 'password' // If a password is required, enter it here.
})
}catch(e){
// If a password is required but not provided, an error occurs.
if (e.code == 'InvalidResource.SharePwd'){
// A password is required.
}
}Parameters
Field | Type | Required | Description |
params | Object | Yes | The parameters. |
options | AxiosRequestConfig | Other configuration items. |
params
Field | Type | Required | Description |
share_id | string | Yes | The share ID. |
share_pwd | string | Access code |
Returns
Field | Type | Required | Description |
result | IShareToken | Yes | The result. |
IShareToken
Field | Type | Required | Description |
share_token | string | Yes | The share token. |
expire_time | string | Yes | The expiration time. |
expires_in | string | Yes | The validity period in seconds. |
Example of using a share token
Retrieves a list of shared files.
const share_token = 'your_share_token'
const share_id = 'your_share_id'
const domain_id = 'your_domain_id'
const client = new PDSClient({
api_endpoint: `https://${domain_id}.api.aliyunpds.com`
})
let {items=[], next_marker} = client.listFiles({
share_id,
parent_file_id: 'root'
}, {
headers: {
'x-share-token': share_token
}
})