This topic describes how to create a symbolic link, and how to obtain the information about the object to which the symbolic link maps.

Create a symbolic link

A symbolic link is a special object that points to an object. It is similar to a shortcut used in Windows. You can use a symbolic link to customize object metadata.

The following code provides an example on how to create a symbolic link:

PutSymlinkRequest putSymlink = new PutSymlinkRequest();
putSymlink.setBucketName("yourBucketName");
//Set the object name for the symbolic link.
putSymlink.setObjectKey("yourSymLink");
//Set the target object name.
putSymlink.setTargetObjectName("yourTargetObjectName");

OSSAsyncTask task = oss.asyncPutSymlink(putSymlink, new OSSCompletedCallback<PutSymlinkRequest,
        PutSymlinkResult>() {
    @Override
    public void onSuccess(PutSymlinkRequest request, PutSymlinkResult result) {
        OSSLog.logInfo("code:"+result.getStatusCode());

    }

    @Override
    public void onFailure(PutSymlinkRequest request, ClientException clientException,
                          ServiceException serviceException) {
        OSSLog.logError("error: "+serviceException.getRawMessage());

    }
});
task.waitUntilFinished();

For more information about how to create a symbolic link, see PutSymlink.

Obtain the information about the object to which the symbolic link maps

To obtain a symbolic link, you must have read permissions on it. Use the following code to obtain the information about the object to which the symbolic link maps:

//Obtain the information about the object to which the symbolic link maps.
GetSymlinkRequest getSymlink = new GetSymlinkRequest();
getSymlink.setBucketName("yourBucketName");
getSymlink.setObjectKey("yourSymLink");

OSSAsyncTask task = oss.asyncGetSymlink(getSymlink, new OSSCompletedCallback<GetSymlinkRequest,
        GetSymlinkResult>() {
    @Override
    public void onSuccess(GetSymlinkRequest request, GetSymlinkResult result) {
        OSSLog.logInfo("targ::"+result.getTargetObjectName());

    }

    @Override
    public void onFailure(GetSymlinkRequest request, ClientException clientException,
                          ServiceException serviceException) {
        OSSLog.logError("error: "+serviceException.getRawMessage());

    }
});
task.waitUntilFinished();

For more information about how to obtain a symbolic link, see GetSymlink.