Soft links
Updated at:2025-11-03
Create a symlink
This API is used to create symlink for an existing target object (referred to as "target object" in this document) in the same bucket. You can access to the target object via the symlink. For the relevant API introduction, see PutSymlink.
Note:
- The symlink file and its target object must reside in the same bucket.
- Symlinks can now be set for object files stored in standard, infrequent access, cold, or archive storage. However, symlinks do not support the ARCHIVE class. If the ARCHIVE class is specified or omitted while the bucket's default storage class is ARCHIVE, an InvalidArgument error will occur.
- When this API is called to create a symlink, it does not verify whether the target file exists or whether there is permission to access it. However, when the GetObject API is called via the symlink, it checks if the user has read permission for both the symlink and the target file, as well as whether the target file exists.
- Creating a symlink requires the appropriate write permission.
- If "forbid_overwrite" is not specified and an object with the same name as the symlink already exists, the existing object will be overwritten by default during the symlink creation process.
- Secondary symlinks are not supported. While no checks are performed when creating a secondary symlink, users will not be able to access the target object data through it.
Optional parameters for creating a symlink:
| Name | Types | Description | Required or not |
|---|---|---|---|
| forbid_overwrite | bool | Specify whether to overwrite an object with the same name when creating a symlink. By default, if x-bce-forbid-overwrite is not specified, overwriting is allowed. If set to true, overwriting is prohibited; if set to false, overwriting is allowed. | No |
| storage_class | string | Set the storage class for the symlink; the archive class is not supported. If unspecified, the storage class of the current bucket will be applied. | No |
| target_bucket | string | Specify the bucket where the symlink target file resides. If not specified, the created symlink and its target file will reside in the same bucket. | No |
An example is as follows:
Python
1symlink_key = "mySymlink"
2bos_client.put_object_from_string(bucket_name, key, "This is string content.")
3# Example 1: Create a symlink
4bos_client.put_object_symlink(bucket_name, key, symlink_key)
5# Example 2: Create a symlink
6bos_client.put_object_symlink(bucket_name, key, symlink_key,
7 forbid_overwrite=Fasle, storage_class=storage_class.STANDARD)
8# Example 3: Create a symlink and specify the bucket of the target file
9bos_client.put_object_from_string(bucket_name, target_key, "This is string content.")
10bos_client.put_object_symlink(bucket_name, target_key, symlink_key, target_bucket=target_bucket)
Retrieve a symlink
This API allows you to retrieve a symlink. You must have read permissions for the symlink to execute this operation.
An example is as follows:
Python
1symlink_key = "mySymlink"
2# Retrieve the symlink and print the target file
3response = bos_client.get_object_symlink(bucket_name, symlink_key)
4print(response.metadata.bce_symlink_target)
5# Retrieve metadata using the symlink
6response = bos_client.get_object_meta_data(bucket_name, symlink_key)
7# If it is a symlink type, return bce_object_type = "Symlink"
8print(response.metadata.bce_object_type)
9# Download the target file using the symlink
10content = bos_client.get_object_as_string(bucket_name, symlink_key)
11print(content)
