Todos os produtos
Search
Central de documentação

Object Storage Service:Symbolic links

Última atualização: Sep 22, 2026

Links simbólicos oferecem uma forma prática de acessar objetos utilizados com frequência em um bucket. Após a criação, o link simbólico funciona como um atalho do Windows, permitindo acesso direto ao objeto de destino.

Notas de uso

  • Objetos das classes Standard ou Infrequent Access podem ser acessados diretamente por meio de seus links simbólicos.

  • Para acessar um objeto das classes Archive, Cold Archive ou Deep Cold Archive por meio de um link simbólico, restaure o objeto primeiro. Para mais informações, consulte Restore objects.

  • Um link simbólico armazena o caminho do objeto de destino, não seu conteúdo. Portanto, o uso de armazenamento do link simbólico depende do comprimento do caminho do objeto de destino, e não do tamanho real desse objeto. Por exemplo, para um link simbólico que aponta para um objeto de 1 MB chamado image.jpg, o próprio link simbólico consome apenas cerca de 0.009 KB de armazenamento.

  • O acesso a um link simbólico segue o princípio do menor privilégio. Em cenários com política de bucket ou política RAM, o usuário precisa ter permissões para acessar tanto o link simbólico quanto o objeto de destino. Se qualquer uma das permissões estiver ausente, o acesso será negado. Em cenários com lista de controle de acesso (ACL), se o link simbólico for privado, o usuário não poderá utilizá-lo para acessar o objeto de destino, mesmo que este seja public-read. Da mesma forma, se o link simbólico for public-read, mas o objeto de destino for privado, o acesso também será negado.

  • Links simbólicos não oferecem suporte a criptografia do lado do servidor.

Procedimento

console do OSS

  1. Faça login no console do OSS.

  2. No painel de navegação à esquerda, clique em Buckets. Na página exibida, clique em no nome do bucket desejado.

  3. Na barra de navegação à esquerda, selecione Object Management

    Objects.

  4. Na coluna Actions do objeto desejado, escolha more > Configure Symbolic Link.

  5. No painel Configure Symbolic Link, defina Symbolic Link File or Folder e clique em OK.

    O nome especificado para o link simbólico deve seguir as convenções de nomenclatura exibidas no console. Considere que o objeto atual está no diretório /test/:

    • Ao selecionar Absolute Path e nomear o link simbólico como t1-symlink, o caminho do link simbólico será /t1-symlink.

    • Ao selecionar Relative Path e nomear o link simbólico como t2-symlink, o caminho do link simbólico será /test/t2-symlink.

    Importante

    Se o nome de arquivo de um link simbólico não incluir uma extensão (por exemplo, o link simbólico do objeto myphoto.jpg recebe o nome myphoto), ainda é possível visualizar o link simbólico acessando-o pelo console ou por uma URL. Ao baixar o link simbólico por meio de uma ferramenta ou do console, o arquivo baixado será considerado de tipo desconhecido e não poderá ser aberto diretamente por não possuir extensão. Para abrir o arquivo, adicione a extensão correta.

ossbrowser

Certifique-se de ter installed ossbrowser 2.0 e logged on to it.

  1. clique em no nome do bucket desejado e localize o objeto de destino.

  2. clique em no ícone image à direita do objeto desejado e clique em Configure Symbolic Link.

  3. Insira o caminho completo do link simbólico, incluindo o nome do arquivo, e clique em OK. Por exemplo, para crie um link simbólico chamado symlink no diretório exampledir/ para o objeto de destino, insira exampledir/symlink.

SDKs do Alibaba Cloud

O código a seguir demonstra como crie um link simbólico usando os SDKs do Alibaba Cloud para linguagens de programação populares. Para informações sobre o uso de SDKs para outras linguagens, consulte SDK overview.

import com.aliyun.oss.*;
import com.aliyun.oss.common.auth.*;
import com.aliyun.oss.common.comm.SignVersion;
import com.aliyun.oss.model.*;

public class Demo {
    public static void main(String[] args) throws Exception {
        // In this example, the endpoint of the China (Hangzhou) region is used. Specify your actual endpoint. 
        String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
        // Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured. 
        EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
        // Specify the name of the bucket. Example: examplebucket. 
        String bucketName = "examplebucket";
        // Specify the name of the symbolic link that you want to create. 
        String symLink = "yourSymLink";
        // Specify the name of the object to which you want the symbolic link to point. 
        String destinationObjectName = "yourDestinationObjectName";
        // 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 cn-hangzhou.
        String region = "cn-hangzhou";

        // Create an OSSClient instance. 
        // Call the shutdown method to release resources when the OSSClient is no longer in use.
        ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration();
        clientBuilderConfiguration.setSignatureVersion(SignVersion.V4);        
        OSS ossClient = OSSClientBuilder.create()
        .endpoint(endpoint)
        .credentialsProvider(credentialsProvider)
        .clientConfiguration(clientBuilderConfiguration)
        .region(region)               
        .build();

        try {
            // Create metadata for the object that you want to upload. 
            ObjectMetadata metadata = new ObjectMetadata();
            metadata.setContentType("text/plain");
            // Set the property parameter for the user metadata to property-value. 
            metadata.addUserMetadata("property", "property-value");

            // Specify whether to overwrite the object that has the same name as the symbolic link. 
            // metadata.setHeader("x-oss-forbid-overwrite", "true");
            // Specify the access control list (ACL) of the object. 
            // metadata.setHeader(OSSHeaders.OSS_OBJECT_ACL, CannedAccessControlList.Default);
            // Specify the storage class of the object. 
            // metadata.setHeader(OSSHeaders.OSS_STORAGE_CLASS, StorageClass.Standard);

            // Create a CreateSymlinkRequest to create the symbolic link. 
            CreateSymlinkRequest createSymlinkRequest = new CreateSymlinkRequest(bucketName, symLink, destinationObjectName);

            // Configure the metadata. 
            createSymlinkRequest.setMetadata(metadata);

            // Create the symbolic link. 
            ossClient.createSymlink(createSymlinkRequest);

        } catch (OSSException oe) {
            System.out.println("Caught an OSSException, which means your request made it to OSS, "
                    + "but was rejected with an error response for some reason.");
            System.out.println("Error Message:" + oe.getErrorMessage());
            System.out.println("Error Code:" + oe.getErrorCode());
            System.out.println("Request ID:" + oe.getRequestId());
            System.out.println("Host ID:" + oe.getHostId());
        } catch (ClientException ce) {
            System.out.println("Caught an ClientException, which means the client encountered "
                    + "a serious internal problem while trying to communicate with OSS, "
                    + "such as not being able to access the network.");
            System.out.println("Error Message:" + ce.getMessage());
        } finally {
            if (ossClient != null) {
                ossClient.shutdown();
            }
        }
    }
}            
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();
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <title>Document</title>
</head>

<body>
  <button id='upload'>Upload</button>
  <button id='symlink'>Create Symbolic Link</button>  
  <!-- Import the SDK file -->
  <script type="text/javascript" src="https://gosspublic.alicdn.com/aliyun-oss-sdk-6.18.0.min.js"></script>
  <script type="text/javascript">
    const client = new OSS({
       // Specify the region in which the bucket is located. For example, if your bucket is located in the China (Hangzhou) region, set the region to oss-cn-hangzhou. 
       region: 'yourRegion',
       authorizationV4: true,
       // Specify the temporary AccessKey pair obtained from STS. The AccessKey pair consists of an AccessKey ID and an AccessKey secret. 
       accessKeyId: 'yourAccessKeyId',
       accessKeySecret: 'yourAccessKeySecret',
       // Specify the security token obtained from STS. 
       stsToken: 'yourSecurityToken',
       // Specify the name of the bucket. Example: examplebucket. 
       bucket: "examplebucket",
     });

    const upload = document.getElementById('upload')
    const symlink = document.getElementById('symlink')
    const getSymlink = document.getElementById("getSymlink")

    // Specify the content of the object to upload. 
    const file = new Blob(['examplecontent'])
    // Specify the name of the object to upload to the bucket. 
    const fileName = 'exampleobject.txt'

    // Upload the object. 
    upload.addEventListener('click', () => {
      client.put(fileName, file).then(r => console.log(r))
    })
    
    // Create a symbolic link named symlink.txt. 
    symlink.addEventListener('click', () => {
      client.putSymlink('symlink.txt', fileName).then(r => console.log(r))
    })

  </script>
</body>

</html>
using Aliyun.OSS;
using System.Text;
using Aliyun.OSS.Common;

// Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com. 
var endpoint = "yourEndpoint";
// Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured. 
var accessKeyId = Environment.GetEnvironmentVariable("OSS_ACCESS_KEY_ID");
var accessKeySecret = Environment.GetEnvironmentVariable("OSS_ACCESS_KEY_SECRET");
// Specify the name of the bucket. Example: examplebucket. 
var bucketName = "examplebucket";
var targetObjectName = "yourTargetObjectName";
var symlinkObjectName = "yourSymlinkObjectName";
var objectContent = "More than just cloud.";
// 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 cn-hangzhou.
const string region = "cn-hangzhou";

// Create a ClientConfiguration instance and modify the default parameters based on your requirements.
var conf = new ClientConfiguration();

// Use the signature algorithm V4.
conf.SignatureVersion = SignatureVersion.V4;

// Create an OSSClient instance.
var client = new OssClient(endpoint, accessKeyId, accessKeySecret, conf);
client.SetRegion(region);
try
{
    // Upload the object to which the symbolic link points. 
    byte[] binaryData = Encoding.ASCII.GetBytes(objectContent);
    MemoryStream requestContent = new MemoryStream(binaryData);
    client.PutObject(bucketName, targetObjectName, requestContent);
    // Create the symbolic link. 
    client.CreateSymlink(bucketName, symlinkObjectName, targetObjectName);
    // Query the name of the object to which the symbolic link points. 
    var ossSymlink = client.GetSymlink(bucketName, symlinkObjectName);
    Console.WriteLine("Target object is {0}", ossSymlink.Target);
}
catch (Exception ex)
{
    Console.WriteLine("Failed with error info: {0}", ex.Message);
}
// Create a request. 
PutSymlinkRequest putSymlink = new PutSymlinkRequest();
// Specify the name of the bucket. 
putSymlink.setBucketName("yourBucketName");
// Specify the name of the symbolic link. 
putSymlink.setObjectKey("yourSymLink");
// Specify the name of the object to which you want the symbolic link to point. 
putSymlink.setTargetObjectName("yourTargetObjectName");

ObjectMetadata metadata = new ObjectMetadata();
// Specify whether to overwrite the object that has the same name. In this example, this parameter is set to true, which indicates that the object that has the same name cannot be overwritten. 
//metadata.setHeader("x-oss-forbid-overwrite", "true");
// Specify the access control list (ACL) of the object. In this example, the ACL is set to private. 
//metadata.setHeader("x-oss-object-acl", "private");
// Specify the storage class of the object. In this example, the storage class is set to Standard. 
//metadata.setHeader("x-oss-storage-class", "Standard");
putSymlink.setMetadata(metadata);

OSSAsyncTask task = oss.asyncPutSymlink(putSymlink, new OSSCompletedCallback<PutSymlinkRequest, PutSymlinkResult>() {
    @Override
    public void onSuccess(PutSymlinkRequest request, PutSymlinkResult result) {
        Log.d("PutSymlink", "PutSymlink success");
    }

    @Override
    public void onFailure(PutSymlinkRequest request, ClientException clientException,
                          ServiceException serviceException) {
        // Handle request exceptions. 
        if (clientException != null) {
            // Handle client exceptions, such as network exceptions. 
            clientException.printStackTrace();
        }
        if (serviceException != null) {
            // Handle server-side exceptions. 
            Log.e("ErrorCode", serviceException.getErrorCode());
            Log.e("RequestId", serviceException.getRequestId());
            Log.e("HostId", serviceException.getHostId());
            Log.e("RawMessage", serviceException.getRawMessage());
        }
    }
});
task.waitUntilFinished();
OSSPutSymlinkRequest *request = [OSSPutSymlinkRequest new];
// Specify the name of the bucket. Example: examplebucket. 
request.bucketName = @"examplebucket";
// Specify the name of the symbolic link. 
request.objectKey = @"examplesymlink";
// Specify the full path of the object to which you want the symbolic link to point. Do not include the bucket name in the full path. 
request.targetObjectName = @"exampleobject.txt";

OSSTask *putSymlinkTask = [client putSymlink:request];
[putSymlinkTask continueWithBlock:^id _Nullable(OSSTask * _Nonnull task) {
    if (!task.error) {
        NSLog(@"put symlink success");
    } else {
        NSLog(@"put symlink failed, error: %@", task.error);
    }
    return nil;
}];
// Implement synchronous blocking to wait for the task to complete. 
// [putSymlinkTask waitUntilFinished];
#include <alibabacloud/oss/OssClient.h>
using namespace AlibabaCloud::OSS;

int main(void)
{
            
    /* Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com. */
    std::string Endpoint = "yourEndpoint";
    /* 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 cn-hangzhou. */
    std::string Region = "yourRegion";
    /* Specify the name of the bucket. Example: examplebucket. */
    std::string BucketName = "examplebucket";
    /* Specify the full path of the object. Example: exampledir/exampleobject.txt. Do not include the bucket name in the full path. */
    std::string ObjectName = "exampledir/exampleobject.txt";
    /* Specify the full path of the symbolic link. Example: shortcut/myobject.txt. */
    std::string LinkName = "shortcut/myobject.txt";

    /* Initialize resources, such as network resources. */
    InitializeSdk();

    ClientConfiguration conf;
    conf.signatureVersion = SignatureVersionType::V4;
    /* Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured. */
    auto credentialsProvider = std::make_shared<EnvironmentVariableCredentialsProvider>();
    OssClient client(Endpoint, credentialsProvider, conf);
    client.SetRegion(Region);

    /* Configure the HTTP headers. */
    auto meta = ObjectMetaData();
    meta.setContentType("text/plain");

    /* Configure the user metadata of the object. */
    meta.UserMetaData()["meta"] = "meta-value";

    /* Create the symbolic link. */
    CreateSymlinkRequest request(BucketName, ObjectName, meta);
    request.SetSymlinkTarget(LinkName);
    auto outcome = client.CreateSymlink(request);

    if (!outcome.isSuccess()) {
        /* Handle exceptions. */
        std::cout << "CreateSymlink fail" <<
        ",code:" << outcome.error().Code() <<
        ",message:" << outcome.error().Message() <<
        ",requestId:" << outcome.error().RequestId() << std::endl;
        return -1;
    }

    /* Release resources, such as network resources. */
    ShutdownSdk();
    return 0;
}
#include "oss_api.h"
#include "aos_http_io.h"
/* Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com. */
const char *endpoint = "yourEndpoint";
/* Specify the name of the bucket. Example: examplebucket. */
const char *bucket_name = "examplebucket";
/* Specify the full path of the object. Do not include the bucket name in the full path. Example: exampledir/exampleobject.txt. */
const char *object_name = "exampledir/exampleobject.txt";
/* Specify the full path of the symbolic link that you want to create. */
const char *link_object_name = "yourLinkObjectName";
/* 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 cn-hangzhou. */
const char *region = "yourRegion";
void init_options(oss_request_options_t *options)
{
    options->config = oss_config_create(options->pool);
    /* Use a char* string to initialize data of the aos_string_t type. */
    aos_str_set(&options->config->endpoint, endpoint);
    /* Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured. */
    aos_str_set(&options->config->access_key_id, getenv("OSS_ACCESS_KEY_ID"));
    aos_str_set(&options->config->access_key_secret, getenv("OSS_ACCESS_KEY_SECRET"));
    // Specify two additional parameters.
    aos_str_set(&options->config->region, region);
    options->config->signature_version = 4;
    /* Specify whether to use CNAME. The value 0 indicates that CNAME is not used. */
    options->config->is_cname = 0;
    /* Specify network parameters, such as the timeout period. */
    options->ctl = aos_http_controller_create(options->pool, 0);
}
int main(int argc, char *argv[])
{
    /* Call the aos_http_io_initialize method in main() to initialize global resources, such as network resources and memory resources. */
    if (aos_http_io_initialize(NULL, 0) != AOSE_OK) {
        exit(1);
    }
    /* Create a memory pool to manage memory. aos_pool_t is equivalent to apr_pool_t. The code used to create a memory pool is included in the APR library. */
    aos_pool_t *pool;
    /* Create a memory pool. The value of the second parameter is NULL. This value indicates that the pool does not inherit other memory pools. */
    aos_pool_create(&pool, NULL);
    /* Create and initialize options. This parameter includes global configuration information, such as endpoint, access_key_id, access_key_secret, is_cname, and curl. */
    oss_request_options_t *oss_client_options;
    /* Allocate the memory resources in the memory pool to the options. */
    oss_client_options = oss_request_options_create(pool);
    /* Initialize oss_client_options. */
    init_options(oss_client_options);
    /* Initialize the parameters. */
    aos_string_t bucket;
    aos_string_t object;
    aos_string_t sym_object;
    aos_table_t *resp_headers = NULL; 
    aos_status_t *resp_status = NULL; 
    aos_str_set(&bucket, bucket_name);
    aos_str_set(&object, object_name);
    aos_str_set(&sym_object, link_object_name);
    resp_status = oss_put_symlink(oss_client_options, &bucket, &sym_object, &object, &resp_headers);
    if (aos_status_is_ok(resp_status)) {
        printf("put symlink succeeded\n");
    } else {
        printf("put symlink failed\n");      
    }
    /* Release the memory pool. This operation releases the memory resources allocated for the request. */
    aos_pool_destroy(pool);
    /* Release the allocated global resources. */
    aos_http_io_deinitialize();
    return 0;
}

ossutil

Use o ossutil para crie links simbólicos. Para mais informações sobre como instale o ossutil, consulte Install ossutil.

O comando a seguir cria um link simbólico chamado examplelink que aponta para o objeto de destino targetobject.

ossutil api put-symlink --bucket examplebucket --key examplelink --symlink-target targetobject

Para mais informações sobre esse comando, consulte put-symlink.

Referência de API

Para personalizações avançadas, você pode fazer requisições diretas à API REST. Isso exige o cálculo manual de uma assinatura no seu código. Para mais informações, consulte PutSymlink.

Perguntas frequentes

Posso crie um link simbólico para um objeto privado?

A criação de um link simbólico independe das permissões de leitura e escrita do objeto de destino. Você pode crie links simbólicos para objetos com qualquer configuração de lista de controle de acesso (ACL), incluindo bucket-owner-full-control, private, public-read e public-read-write.

Como determinar se um objeto é um link simbólico?

Chame a operação HeadObject ou GetObject e verifique a resposta.

Se o objeto for um link simbólico, a resposta conterá o conteúdo do objeto de destino. Os cabeçalhos Content-Length, ETag e Content-Md5 na resposta correspondem aos metadados do objeto de destino.

Se eu exclua um link simbólico, o objeto de destino também será excluído?

Não. A exclusão de um link simbólico remove apenas o próprio link, sem afetar o objeto de destino.