Object Storage Service (OSS) provides multiple storage classes, such as Standard, Infrequent Access, Archive, Cold Archive, and Deep Cold Archive, to meet various storage requirements for data ranging from hot to cold data. In OSS, the content of an object is immutable after it is created. This means that to change the storage class of an object, you cannot directly modify the original object but must create a new one. This topic describes how to use the Copier.Copy method or the Client.CopyObject method in Go SDK V2 to convert the storage class of an object by copying the source object.
Usage notes
The sample code in this topic uses the
cn-hangzhouregion ID for the China (Hangzhou) region. By default, a public endpoint is used to access resources in a bucket. If you access resources in the bucket from other Alibaba Cloud services in the same region, use an internal endpoint. For more information about the regions and endpoints that OSS supports, see OSS regions and endpoints.In this topic, access credentials are retrieved from environment variables. For more information about how to configure access credentials, see Configure access credentials.
To convert the storage class of an object, you must have the
oss:GetObject,oss:PutObject, andoss:RestoreObjectpermissions. For more information, see Grant a custom policy to a RAM user.
Sample code
References
For more information about the API operation to convert the storage class of an object using the Copier, see Copier.Copy.
For more information about the API operation to convert the storage class of an object using the simple copy method, see CopyObject.