Todos os produtos
Search
Central de documentação

Object Storage Service:Manage symbolic links using OSS SDK for C# 1.0

Última atualização: Jul 03, 2026

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

Observações

  • Este tópico usa o endpoint público da região China (Hangzhou). Para acessar o OSS a partir de outros serviços da Alibaba Cloud na mesma região, use um endpoint interno. Para obter mais informações sobre regiões e endpoints do OSS, consulte Regiões e endpoints.

  • Este tópico demonstra a criação de uma instância OSSClient com um endpoint do OSS. Para outras configurações, como uso de domínio personalizado ou autenticação com credenciais do Security Token Service (STS), consulte Inicialização (C# SDK V1).

  • Para criar um link simbólico, você precisa da permissão oss:PutObject. Para consultar um link simbólico, é necessária a permissão oss:GetObject. Para obter mais informações, consulte Conceder uma política personalizada.

Código de exemplo

O código a seguir mostra como criar um link simbólico e consultar o nome do objeto ao qual ele aponta:

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);
}

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.