All Products
Search
Document Center

Object Storage Service:Real-time access to Archive objects (OSS SDK for Go V2)

Last Updated:Mar 20, 2026

By default, Archive objects in Object Storage Service (OSS) are not immediately readable — reading them requires a restore operation before data becomes available. Real-time access removes this restriction at the bucket level, letting your application read Archive objects directly without a restore wait. Use the OSS SDK for Go V2 to enable or disable this feature, and to check the current configuration.

Prerequisites

Before you begin, make sure you have:

Usage notes

  • The sample code uses the region ID cn-hangzhou for the China (Hangzhou) region. Replace it with your bucket's region ID.

  • By default, code samples access the bucket through a public endpoint. To access the bucket from another Alibaba Cloud service in the same region, use an internal endpoint instead. For supported regions and endpoints, see OSS regions and endpoints.

Both samples below share the same client setup: credentials are loaded from environment variables, the region is passed as a command-line flag, and the OSS client is created from the resulting configuration.

Enable real-time access

Core call

request := &oss.PutBucketArchiveDirectReadRequest{
    Bucket: oss.Ptr(bucketName),
    ArchiveDirectReadConfiguration: &oss.ArchiveDirectReadConfiguration{
        Enabled: oss.Ptr(true), // Set to false to disable real-time access.
    },
}
result, err := client.PutBucketArchiveDirectRead(context.TODO(), request)

Complete sample

package main

import (
	"context"
	"flag"
	"log"

	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)

var (
	region     string
	bucketName string
)

func init() {
	flag.StringVar(&region, "region", "", "The region in which the bucket is located.")
	flag.StringVar(&bucketName, "bucket", "", "The name of the bucket.")
}

func main() {
	flag.Parse()

	if len(bucketName) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, bucket name required")
	}

	if len(region) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, region required")
	}

	// Load credentials from environment variables and set the region.
	cfg := oss.LoadDefaultConfig().
		WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
		WithRegion(region)

	client := oss.NewClient(cfg)

	// Enable real-time access for Archive objects in the bucket.
	request := &oss.PutBucketArchiveDirectReadRequest{
		Bucket: oss.Ptr(bucketName),
		ArchiveDirectReadConfiguration: &oss.ArchiveDirectReadConfiguration{
			Enabled: oss.Ptr(true), // Set to false to disable real-time access.
		},
	}
	result, err := client.PutBucketArchiveDirectRead(context.TODO(), request)
	if err != nil {
		log.Fatalf("failed to put bucket archive direct read %v", err)
	}

	log.Printf("put bucket archive direct read result:%#v\n", result)
}

Query real-time access status

Core call

request := &oss.GetBucketArchiveDirectReadRequest{
    Bucket: oss.Ptr(bucketName),
}
result, err := client.GetBucketArchiveDirectRead(context.TODO(), request)

Complete sample

package main

import (
	"context"
	"flag"
	"log"

	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)

var (
	region     string
	bucketName string
)

func init() {
	flag.StringVar(&region, "region", "", "The region in which the bucket is located.")
	flag.StringVar(&bucketName, "bucket", "", "The name of the bucket.")
}

func main() {
	flag.Parse()

	if len(bucketName) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, bucket name required")
	}

	if len(region) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, region required")
	}

	// Load credentials from environment variables and set the region.
	cfg := oss.LoadDefaultConfig().
		WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
		WithRegion(region)

	client := oss.NewClient(cfg)

	// Query the real-time access configuration for Archive objects in the bucket.
	request := &oss.GetBucketArchiveDirectReadRequest{
		Bucket: oss.Ptr(bucketName),
	}
	result, err := client.GetBucketArchiveDirectRead(context.TODO(), request)
	if err != nil {
		log.Fatalf("failed to get bucket archive direct read %v", err)
	}

	log.Printf("get bucket archive direct read result:%#v\n", result)
}

References