Note
-
To retrieve a symbolic link, you must have read permissions on the symbolic link itself.
-
The GetSymlink API retrieves the current version of the symbolic link by default. You can specify a version ID to retrieve a specific version. If the current version of the symbolic link is a delete marker, OSS returns a 404 Not Found, with x-oss-delete-marker = true and the version ID: x-oss-version-id in the response header.
You can use the following code to retrieve a symbolic link.
import argparse
import alibabacloud_oss_v2 as oss
# Create a command line argument parser and describe the script's purpose: retrieve symbolic link information
parser = argparse.ArgumentParser(description="get symlink sample")
# Add command line argument --region, indicating the region where the bucket is located, required parameter
parser.add_argument('--region', help='The region in which the bucket is located.', required=True)
# Add command line argument --bucket, indicating the name of the bucket, required parameter
parser.add_argument('--bucket', help='The name of the bucket.', required=True)
# Add command line argument --endpoint, indicating the domain names that other services can use to access OSS, optional parameter
parser.add_argument('--endpoint', help='The domain names that other services can use to access OSS')
# Add command line argument --key, indicating the name of the object, required parameter
parser.add_argument('--key', help='The name of the object.', required=True)
# Add command line argument --version_id, indicating the version ID of the object, required parameter
parser.add_argument('--version_id', help='The version id of the object.', required=True)
def main():
# Parse the command line arguments to obtain the values entered by the user
args = parser.parse_args()
# Load the authentication information required to access OSS from environment variables for authentication
credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()
# Create a configuration object using the default configuration of the SDK and set the credentials provider
cfg = oss.config.load_default()
cfg.credentials_provider = credentials_provider
# Set the region property of the configuration object based on the command line arguments provided by the user
cfg.region = args.region
# If a custom endpoint is provided, update the endpoint property in the configuration object
if args.endpoint is not None:
cfg.endpoint = args.endpoint
# Initialize the OSS client using the above configuration to prepare for interaction with OSS
client = oss.Client(cfg)
# Send a request to retrieve the symbolic link information
result = client.get_symlink(oss.GetSymlinkRequest(
bucket=args.bucket, # Specify the bucket name
key=args.key, # Specify the symbolic link object name
version_id=args.version_id # Specify the version ID of the symbolic link object
))
# Print the status code, request ID, version ID, target object, and ETag of the operation result to confirm the request status
print(f'status code: {result.status_code},'
f' request id: {result.request_id},'
f' version id: {result.version_id},'
f' target: {result.target},'
f' etag: {result.etag},'
)
# When this script is executed directly, call the main function to start processing logic
if __name__ == "__main__":
main() # Script entry point, control program flow starts here