Symbolic links can be used to access objects that are frequently used in buckets. After you create a symbolic link for an object, you can use the symbolic link to access the object.

Create a symbolic link

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

const OSS = require('ali-oss')

const client = new OSS({
  // Set yourRegion to the endpoint of the region in which the bucket is located. For example, if your bucket is located in the China (Hangzhou) region, set yourRegion to oss-cn-hangzhou. 
  region: 'yourRegion',
  // Security risks may arise if you use the AccessKey pair of an Alibaba Cloud account to access Object Storage Service (OSS) because the account has permissions on all API operations. We recommend that you use a RAM user to call API operations or perform routine operations and maintenance. To create a RAM user, log on to the RAM console. 
  accessKeyId: 'yourAccessKeyId',
  accessKeySecret: 'yourAccessKeySecret',
  // Specify the bucket name. 
  bucket: 'examplebucket',
});

const headers = {
   // Specify the storage class of the object. 
   'x-oss-storage-class':'Standard', 
   // Specify the access control list (ACL) of the object. 
   'x-oss-object-acl':'private',
   // Specify whether to overwrite the object with the same name when you create a symbolic link. If you set x-oss-forbid-overwrite to true, the object with the same name cannot be overwritten. 
   'x-oss-forbid-overwrite': 'true '
};

async function put () {
  try {
    // Specify symlinkobject.txt as the name of the symbolic link and exampleobject.txt as the name of the object to which the symbolic link points.  
    const result = await client.putSymlink('symlinkobject.txt', 'exampleobject.txt'
    // ,{ headers }
    );
    console.log(result);
  } catch (e) {
    console.log(e);
  }
}

put();

Query the name of the object to which the symbolic link points

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

const OSS = require('ali-oss')

const client = new OSS({
  // Set yourRegion to the endpoint of the region in which the bucket is located. For example, if your bucket is located in the China (Hangzhou) region, set yourRegion to oss-cn-hangzhou. 
  region: 'yourRegion',
  // Security risks may arise if you use the AccessKey pair of an Alibaba Cloud account to access OSS because the account has permissions on all API operations. We recommend that you use a RAM user to call API operations or perform routine operations and maintenance. To create a RAM user, log on to the RAM console. 
  accessKeyId: 'yourAccessKeyId',
  accessKeySecret: 'yourAccessKeySecret',
  // Specify the bucket name. 
  bucket: 'examplebucket',
});

// Specify the name of the symbolic link and query the name of the object to which the symbolic link points. 
store.getSymlink('symlinkobject.txt').then(r=>console.log(r))

References

  • For more information about the API operation that you can call to create a symbolic link, see PutSymlink.
  • For more information about the API operation that you can call to query a symbolic link, see GetSymlink.