This topic describes how to create a symbolic link and obtain the name of the object to which the symbolic link points.

Create a symbolic link

A symbolic link is a special object that points to an object. It is similar to a shortcut used in Windows. You can use a symbolic link to customize object metadata.

The following code provides an example on how to create a symbolic link:

const oss = require('ali-oss');

const store = oss({
// Security risks may arise if you use the AccessKey pair of an Alibaba Cloud account to log on to OSS, because the account has permissions on all API operations. We recommend that you log on to the OSS console as a RAM user to call API operations or perform routine operations and maintenance. To create a RAM user, log on to https://ram.console.aliyun.com.
  accessKeyId: '<your access key>',
  accessKeySecret: '<your access secret>',
  bucket: '<your bucket name>',
  // Obtain the region where the current bucket is located.
  region: 'oss-cn-hangzhou'
});
const options = {
  storageClass: 'IA',
  meta: {
    uid: '1',
    slus: 'test.html'
  }
}
const result = await store.putSymlink('<object name>', '<target object mame>', options)

For more information about how to create a symbolic link, see PutSymlink.

Obtain the name of the object to which a symbolic link directs

To obtain a symbolic link, you must have read permissions on it. The following code provides an example on how to obtain the name of the object to which a symbolic link directs:

const oss = require('ali-oss');

const store = oss({
// Security risks may arise if you use the AccessKey pair of an Alibaba Cloud account to log on to OSS, because the account has permissions on all API operations. We recommend that you log on to the OSS console as a RAM user to call API operations or perform routine operations and maintenance. To create a RAM user, log on to https://ram.console.aliyun.com.
  accessKeyId: '<your access key>',
  accessKeySecret: '<your access secret>',
  bucket: '<your bucket name>',
  // Obtain the region where the current bucket is located.
  region: 'oss-cn-hangzhou'
});
const result = await store.getSymlink('<object name>')
console.log(result.targetName)

For more information about how to obtain a symbolic link, see GetSymlink.