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:
Access credentials configured as environment variables. For details, see Configure access credentials
Usage notes
The sample code uses the region ID
cn-hangzhoufor 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.
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(®ion, "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
For the complete sample code, see GitHub example.
For the API operation to enable real-time access, see PutBucketArchiveDirectRead.
For the API operation to query the real-time access configuration, see GetBucketArchiveDirectRead.