Updated on 2026-08-14 GMT+08:00

Configuring Direct Reading for a Bucket

Function

The direct reading function means that you can directly perform operations on Archive objects without restoring them.

By default, direct reading is disabled for a bucket.

This API is used to enable or disable direct reading for a bucket.

  • When direct reading is enabled on a bucket:
    • You can directly perform operations on the Archive objects in the bucket regardless of whether they have been restored.
    • Operations on the Archive objects that are not restored will be billed separately.
  • When direct reading is enabled on a bucket:
    • You need to restore objects in the bucket before you can operate them.

Direct reading means that you can directly perform operations on objects without restoring them. For more information about direct reading, see Direct Reading.

Restrictions

Method

func (obsClient ObsClient) SetBucketDirectColdAccess(input *SetBucketDirectColdAccessInput) (output *BaseModel, err error)

Request Parameters

Table 1 List of request parameters

Parameter

Type

Mandatory (Yes/No)

Description

input

*SetBucketDirectColdAccessInput

Yes

Explanation:

Request parameter for configuring direct reading for a bucket. For details, see Table 2.

Restrictions:

None

Value range:

None

Default value:

None

Table 2 SetBucketDirectColdAccessInput

Parameter

Type

Mandatory (Yes/No)

Description

Bucket

string

Yes

Explanation:

Bucket name.

Restrictions:

  • A bucket name must be unique across all accounts and regions.
  • A bucket name:
    • Must be 3 to 63 characters long and start with a digit or letter. Lowercase letters, digits, hyphens (-), and periods (.) are allowed.
    • Cannot be formatted as an IP address.
    • Cannot start or end with a hyphen (-) or period (.).
    • Cannot contain two consecutive periods (..), for example, my..bucket.
    • Cannot contain a period (.) and a hyphen (-) adjacent to each other, for example, my-.bucket or my.-bucket.
  • If you repeatedly create buckets with the same name in the same region, no error will be reported and the bucket properties comply with those set in the first creation request.

Value range:

None

Default value:

None

DirectColdAccessConfiguration

DirectColdAccessConfiguration

Yes

Explanation:

Direct reading configuration of Archive objects in a bucket.

Restrictions:

None

Value range:

See Table 3.

Default value:

None

Table 3 DirectColdAccessConfiguration

Parameter

Type

Mandatory (Yes/No)

Description

Status

DirectColdAccessStatus

Yes

Explanation:

Direct reading status of a bucket

Restrictions:

None

Value range:

See Table 4.

Default value:

None

Table 4 DirectColdAccessStatus

Constant

Original Value

Description

DirectColdAccessStatusEnabled

Enabled

Direct reading is enabled for the bucket.

DirectColdAccessStatusDisabled

Disabled

Direct reading is disabled for the bucket.

Responses

Table 5 List of returned results

Parameter

Type

Description

output

*BaseModel

Explanation:

Returned results. For details, see Table 6.

Value range:

None

err

error

Explanation:

The error message returned by the server.

Value range:

None

Table 6 BaseModel

Parameter

Type

Description

StatusCode

int

Explanation:

HTTP status code

Restrictions:

None

Value range:

A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. For more information, see Status Code.

Default value:

None

RequestId

string

Explanation:

Request ID returned by the OBS server

Restrictions:

None

Value range:

None

Default value:

None

ResponseHeaders

map[string][]string

Explanation:

HTTP response headers

Restrictions:

None

Value range:

None

Default value:

None

Sample Code

This example configures direct reading for bucket examplebucket.
package main
import (
    "fmt"
    "os"

    obs "github.com/huaweicloud/huaweicloud-sdk-go-obs/obs"
)
func main() {
    // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage.
    // Obtain an AK/SK pair on the management console. For details, see https://support.huaweicloud.com/intl/en-us/usermanual-ca/ca_01_0003.html.
    ak := os.Getenv("AccessKeyID")
    sk := os.Getenv("SecretAccessKey")
    // (Optional) If you use a temporary AK/SK pair and a security token to access OBS, you are not advised to use hard coding, which may result in information leakage. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways.
    securityToken := os.Getenv("SecurityToken")


    // Enter the endpoint corresponding to the bucket. CN-Hong Kong is used here as an example. Replace it with the one currently in use.
    endPoint := "https://obs.ap-southeast-1.myhuaweicloud.com"




    // Create an obsClient instance.
    // If you use a temporary AK/SK pair and a security token to access OBS, use the obs.WithSecurityToken method to specify a security token when creating an instance.
    obsClient, err := obs.New(ak, sk, endPoint, obs.WithSecurityToken(securityToken))
    if err != nil {
        fmt.Printf("Create obsClient error, errMsg: %s", err.Error())
    }
    input := &obs.SetBucketDirectColdAccessInput{}
    // Specify a bucket name.
    input.Bucket = "examplebucket"
    // Specify the status.
    input.DirectColdAccessConfiguration.Status = obs.DirectColdAccessStatusEnabled
    // Configure direct reading for the bucket.
    output, err := obsClient.SetBucketDirectColdAccess(bucketName)
    if err == nil {
	fmt.Printf("Set bucket(%s)'s direct cold successful!\n", bucketName)
	fmt.Printf("RequestId:%s\n", output.RequestId)
	return
    }
    fmt.Printf("Set bucket(%s)'s direct cold fail!\n", bucketName)
    if obsError, ok := err.(obs.ObsError); ok {
	fmt.Println("An ObsError was found, which means your request sent to OBS was rejected with an error response.")
	fmt.Println(obsError.Error())
    } else {
	fmt.Println("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network.")
	fmt.Println(err)
    }
}