Symbolic links can be used to access objects that are frequently used in buckets. After you create a symbolic link for an object, you can use the symbolic link to access the object.

Create a symbolic link

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

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. 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;
}];

Query a symbolic link

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

The following code is used to obtain the name of the object pointed to by the symbolic link examplesymlink in the examplebucket bucket.

OSSGetSymlinkRequest *request = [OSSGetSymlinkRequest new];
// Specify the name of the bucket. 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;
}];

References

  • For more information about the API operation that you can call to create a symbolic link, see PutSymlink.
  • For more information about the API operation that you can call to query a symbolic link, see GetSymlink.