Copy objects within a bucket or between buckets in the same region.
Usage notes
-
In this topic, the public endpoint of the China (Hangzhou) region is used. If you want to access OSS from other Alibaba Cloud services in the same region as OSS, use an internal endpoint. For more information about OSS regions and endpoints, see Regions and Endpoints.
-
In this topic, access credentials are obtained from environment variables. For more information about how to configure access credentials, see Configure access credentials.
-
This topic demonstrates creating an OSSClient instance with an OSS endpoint. For alternative configurations, such as using a custom domain or authenticating with credentials from Security Token Service (STS), see Configure a client (Go SDK V1).
-
You must have read permissions on the source object and read/write permissions on the destination bucket.
-
The source and destination buckets must not have retention policies configured. Otherwise, the copy fails and the error The object you specified is immutable. is returned.
-
Cross-region copy is not supported. For example, you cannot copy an object from a China (Hangzhou) bucket to a China (Qingdao) bucket.
Sample code
References
-
Complete sample code for copying objects: GitHub sample.
-
API reference for small object copy: CopyObject.
-
API reference for large object copy (multipart): UploadPartCopy.