You can configure a symbolic link to point to a frequently accessed object in the target bucket for easier object retrieval. After configuring a symbolic link for an object, you can use the symbolic link to quickly access the object. A symbolic link works in a similar manner as the shortcut in Windows. This topic describes how to manage symbolic links in a versioning-enabled bucket.
Create a symbolic link
The following code provides an example on how to create a symbolic link:
using Aliyun.OSS;
var endpoint = "<yourEndpoint>";
var accessKeyId = "<yourAccessKeyId>";
var accessKeySecret = "<yourAccessKeySecret>";
var bucketName = "<yourBucketName>";
var targetObjectName = "<yourTargetObjectName>";
var symlinkObjectName = "<yourSymlinkObjectName>";
var objectContent = "More than just cloud." ;
// Create an OSSClient instance.
var client = new OssClient(endpoint, accessKeyId, accessKeySecret);
try
{
// Upload the target object.
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);
}
catch (Exception ex)
{
Console.WriteLine("Failed with error info: {0}", ex.Message);
}
For more information about how to create a symbolic link, see PutSymlink.
Obtain symbolic links
The following code provides an example on how to obtain a symbolic link:
using Aliyun.OSS;
var endpoint = "<yourEndpoint>";
var accessKeyId = "<yourAccessKeyId>";
var accessKeySecret = "<yourAccessKeySecret>";
var bucketName = "<yourBucketName>";
var symlinkObjectName = "<yourSymlinkObjectName>";
var versionid = "<yourArchiveObjectVersionid>";
// Create an OSSClient instance.
var client = new OssClient(endpoint, accessKeyId, accessKeySecret);
try
{
// Obtain the name of the object to which the symbolic link points.
var request = new GetSymlinkRequest(bucketName, symlinkObjectName)
{
// Obtain the specified version of a symbolic link.
VersionId = versionid
};
var ossSymlink = client.GetSymlink(request);
Console.WriteLine("Target object is {0}", ossSymlink.Target);
}
catch (Exception ex)
{
Console.WriteLine("Failed with error info: {0}", ex.Message);
}
For more information about how to obtain a symbolic link, see GetSymlink.