对冷归档对象进行恢复,恢复之后可以通过下载对象接口获取到对象。通过参数可以指定不同的取回方式。
以下代码用于恢复对象。
package main import ( "context" "fmt" "github.com/volcengine/ve-tos-golang-sdk/v2/tos" "github.com/volcengine/ve-tos-golang-sdk/v2/tos/enum" ) func checkErr(err error) { if err != nil { if serverErr, ok := err.(*tos.TosServerError); ok { fmt.Println("Error:", serverErr.Error()) fmt.Println("Request ID:", serverErr.RequestID) fmt.Println("Response Status Code:", serverErr.StatusCode) fmt.Println("Response Header:", serverErr.Header) fmt.Println("Response Err Code:", serverErr.Code) fmt.Println("Response Err Msg:", serverErr.Message) } else { fmt.Println("Error:", err) } panic(err) } } func main() { var ( accessKey = os.Getenv("TOS_ACCESS_KEY") secretKey = os.Getenv("TOS_SECRET_KEY") // Bucket 对于的 Endpoint,以华北2(北京)为例:https://tos-cn-beijing.volces.com endpoint = "https://tos-cn-beijing.volces.com" region = "cn-beijing" // 填写 BucketName bucketName = "*** Provide your bucket name ***" key = "restore-key" versionId = "restore-version-id" ctx = context.Background() ) // 初始化客户端 client, err := tos.NewClientV2(endpoint, tos.WithRegion(region), tos.WithCredentials(tos.NewStaticCredentials(accessKey, secretKey))) checkErr(err) // 恢复对象 output, err := client.RestoreObject(ctx, &tos.RestoreObjectInput{ Bucket: bucketName, Key: key, VersionID: versionId, Days: 1, RestoreJobParameters: &tos.RestoreJobParameters{ Tier: enum.TierStandard, }, }) checkErr(err) fmt.Println("RestoreObject Request ID:", output.RequestID) }
关于恢复对象接口的详细介绍,请参见 RestoreObject。