Todos os produtos
Search
Central de documentação

Object Storage Service:Manage symbolic links using OSS SDK for Node.js

Última atualização: Jul 03, 2026

Os links simbólicos funcionam como atalhos de arquivo no Windows e permitem acessar rapidamente objetos associados no Object Storage Service (OSS).

Criar um link simbólico

O código de exemplo a seguir mostra como criar um link simbólico:

const OSS = require('ali-oss')

const client = new OSS({
  // Specify the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the region to oss-cn-hangzhou. 
  region: 'yourRegion',
  // Obtain access credentials from environment variables. Before you run the sample code, make sure that you have configured environment variables OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET. 
  accessKeyId: process.env.OSS_ACCESS_KEY_ID,
  accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET,
  authorizationV4: true,
  // Specify the name of the bucket. 
  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 that has the same name as the symbolic link. In this example, this parameter is set to true, which indicates that 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 you want the symbolic link to point.  
    const result = await client.putSymlink('symlinkobject.txt', 'exampleobject.txt'
    // ,{ headers }
    );
    console.log(result);
  } catch (e) {
    console.log(e);
  }
}

put();

Consultar o nome do objeto apontado pelo link simbólico

Para consultar um link simbólico, você precisa ter permissões de leitura sobre ele. O código a seguir mostra como obter o nome do objeto para o qual o link simbólico aponta:

const OSS = require('ali-oss')

const client = new OSS({
  // Specify the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the region to oss-cn-hangzhou. 
  region: 'yourRegion',
  // Obtain access credentials from environment variables. Before you run the sample code, make sure that you have configured environment variables OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET. 
  accessKeyId: process.env.OSS_ACCESS_KEY_ID,
  accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET,
  authorizationV4: true,
  // Specify the name of the bucket. 
  bucket: 'examplebucket',
});

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

Referências

  • Para obter mais informações sobre a operação de API usada para criar um link simbólico, consulte PutSymlink.

  • Para obter mais informações sobre a operação de API usada para consultar um link simbólico, consulte GetSymlink.