All Products
Search
Document Center

Object Storage Service:Manage symbolic links (iOS SDK)

Last Updated:Nov 29, 2025

Symbolic links work like file shortcuts on Windows and allow you to quickly access associated objects in Object Storage Service (OSS).

Usage notes

  • Before you use the examples in this topic, you must create an OSSClient instance using a custom domain name or Security Token Service (STS). For more information, see Initialization (iOS SDK).

Create a symbolic link

The following code provides an example of how to create a symbolic link named examplesymlink. The symbolic link points to the exampleobject.txt object in the examplebucket bucket.

OSSPutSymlinkRequest *request = [OSSPutSymlinkRequest new];
// Specify the bucket name. 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. The full path cannot contain the bucket name.
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];

Get a symbolic link

To retrieve the object that a symbolic link points to, you must have read permissions on the symbolic link.

The following code shows how to retrieve the name of the object that the examplesymlink symbolic link points to. The symbolic link is in the examplebucket bucket.

OSSGetSymlinkRequest *request = [OSSGetSymlinkRequest new];
// Specify the bucket name. Example: examplebucket.
request.bucketName = @"examplebucket";
// Specify the name of the symbolic link.
request.objectKey = @"examplesymlink";

OSSTask *getSymlinkTask = [client getSymlink:request];
[getSymlinkTask continueWithBlock:^id _Nullable(OSSTask * _Nonnull task) {
    if (!task.error) {
        OSSGetSymlinkResult *result = task.result;
        NSLog(@"get symlink: %@", result.httpResponseHeaderFields[@"x-oss-symlink-target"]);
    } else {
        NSLog(@"get symlink failed, error: %@", task.error);
    }
    return nil;
}];
// Implement synchronous blocking to wait for the task to complete.
// [putSymlinkTask waitUntilFinished];

References