Restoring archived objects

Last updated: 2023-09-13 14:07:47

Feature Overview

This document provides an overview of APIs and SDK code samples for restoring an archived object.
API
Operation
Description
Restoring archived objects
Restores archived object for access

Restoring archived objects

Note

This API is used to restore an archived object for access.

Method prototype

func (s *ObjectService) PostRestore(ctx context.Context, key string, opt *ObjectRestoreOptions) (*Response, error)

Sample Request

package main

import (
"context"
"github.com/tencentyun/cos-go-sdk-v5"
"net/http"
"net/url"
"os"
)

func main() {
// Bucket name, composed of bucketname-appid, appid is required. The bucket name can be viewed in the COS console: https://console.cloud.tencent.com/cos5/bucket
// Replace with the user's region. The bucket region can be viewed in the COS console "Bucket Overview" at https://console.cloud.tencent.com/. For more information about regions, visit https://cloud.tencent.com/document/product/436/6224.
u, _ := url.Parse("https://examplebucket-1250000000.cos.ap-guangzhou.myqcloud.com")
b := &cos.BaseURL{BucketURL: u}
client := cos.NewClient(b, &http.Client{
Transport: &cos.AuthorizationTransport{
// Get the key from environment variables
// Environment variable SECRETID represents the user's SecretId. To view the key, log in to the Access Management Console at https://console.cloud.tencent.com/cam/capi.
SecretID: os.Getenv("SECRETID"), // User's SecretId, it is recommended to use a sub-account key, following the principle of least privilege to reduce usage risks. For obtaining a sub-account key, please refer to https://cloud.tencent.com/document/product/598/37140
// The environment variable SECRETKEY represents the user's SecretKey. To view the key, log in to the CAM console at https://console.cloud.tencent.com/cam/capi.
SecretKey: os.Getenv("SECRETKEY"), // User's SecretKey, it is recommended to use a sub-account key, following the principle of least privilege to reduce usage risks. For obtaining a sub-account key, please refer to https://cloud.tencent.com/document/product/598/37140
},
})
key := "example_restore"
f, err := os.Open("/test")
if err != nil {
panic(err)
}
opt := &cos.ObjectPutOptions{
ObjectPutHeaderOptions: &cos.ObjectPutHeaderOptions{
ContentType: "text/html",
XCosStorageClass: "ARCHIVE", // Archive type
},
ACLHeaderOptions: &cos.ACLHeaderOptions{
// It is recommended not to set permissions for individual files during upload unless necessary, to avoid reaching the limit. If not set, the file will inherit the bucket's permissions by default.
XCosACL: "private",
},
}
// Direct archive upload
_, err = client.Object.Put(context.Background(), key, f, opt)
if err != nil {
panic(err)
}

opts := &cos.ObjectRestoreOptions{
Days: 2,
Tier: &cos.CASJobParameters{
// Standard, Expedited and Bulk
Tier: "Expedited",
},
}
// Archive restoration
_, err = client.Object.PostRestore(context.Background(), key, opts)
if err != nil {
panic(err)
}
}

Description

type ObjectRestoreOptions struct {
Days int
Tier *CASJobParameters
}
type CASJobParameters struct {
Tier string
}
Parameter name
ParameterDescription
Local Disk Types
Required
key
ObjectKey is the unique identifier of the object in the bucket. For example, in the object's access domain name examplebucket-1250000000.cos.ap-guangzhou.myqcloud.com/doc/pic.jpg, the ObjectKey is doc/pic.jpg
string
Required
ObjectRestoreOptions
Describes rules for retrieved temporary files
struct
Required
Days
Specifies the number of days before a temporary object expires
int
Required
CASJobParameters
Describes the configuration of the restoration type
struct
Not required
Tier
Describing the retrieval mode for temporary files.
For restoring archived storage data, the optional values are Expedited, Standard, and Bulk, corresponding to the three modes: expedited retrieval, standard retrieval, and bulk retrieval.
For restoring data from deep archive storage, the available options are Standard and Bulk.
string
Not required