OSS does not support direct object renaming. To rename an object within the same bucket, use the CopyObject operation to copy the source object to a destination object with a new name.
Usage notes
The sample code uses the public endpoint for the China (Hangzhou) region (
cn-hangzhou) by default. To access OSS from another Alibaba Cloud service in the same region, use the internal endpoint. For a full list of regions and endpoints, see OSS regions and endpoints.All examples use
EnvironmentVariableCredentialsProviderto load credentials from environment variables, avoiding hardcoded keys.
Sample code
What's next
Delete objects — delete the source object after a successful copy to complete the rename
Copy objects — more options for cross-bucket and cross-region copies