Help Center/ Object Storage Service/ SDK Reference/ C/ Bucket APIs (SDK for C)/ Direct Reading (SDK for C)/ Obtaining the Direct Reading Configuration of Archive Storage Objects in a Bucket (SDK for C)
Updated on 2026-11-17 GMT+08:00

Obtaining the Direct Reading Configuration of Archive Storage Objects in a Bucket (SDK for C)

If you have any questions during development, post them on the Issues page of GitHub.

Function

A bucket owner can call this API to obtain the direct reading status of Archive Storage objects in the bucket.

If direct reading has never been configured for Archive Storage objects in the bucket or the direct reading configuration has been deleted, no direct reading status will be returned after this API call.

Restrictions

Method

void get_bucket_direct_cold_access(const obs_options *options,
    obs_get_bucket_direct_cold_access_handler *handler, void *callback_data);

Request Parameters

Table 1 List of request parameters

Parameter

Type

Mandatory (Yes/No)

Description

options

const obs_options*

Yes

Explanation:

Context of the requested bucket. You can set the AK, SK, endpoint, bucket, timeout interval, and temporary credentials through obs_options.

Restrictions:

None

Value range:

None

Default value:

None

handler

obs_get_bucket_direct_cold_access_handler *

Yes

Explanation:

A callback structure where all members are pointers to callback functions, used to set the callback functions that handle response data. You can set a callback function to copy the response data from the server to callback_data (custom callback data).

Restrictions:

None

Value range:

None

Default value:

None

callback_data

void *

No

Explanation:

Custom callback data.

Restrictions:

None

Value range:

None

Default value:

None

Table 2 obs_get_bucket_direct_cold_access_handler

Parameter

Type

Mandatory (Yes/No)

Description

response_handler

obs_response_handler

Yes

Explanation:

Response callback function structure.

Restrictions:

None

Value range:

None

Default value:

None

get_bucket_direct_cold_access_callback

Table 3*

Yes

Explanation:

Pointer to the callback function of the direct reading policy for Archive Storage objects. In this callback, you can record the content of direct_cold_access_status into callback_data (custom callback data).

Restrictions:

None

Value range:

None

Default value:

None

Table 3 obs_get_bucket_direct_cold_access_callback

Parameter

Type

Mandatory (Yes/No)

Description

direct_cold_access_status

const char *

Yes

Explanation:

Status of the direct reading policy for Archive Storage objects.

Restrictions:

None

Value range:

Enabled: The direct reading policy is enabled for Archive Storage objects.

Disabled: The direct reading policy is disabled for Archive Storage objects.

Empty string: No direct reading policy is configured for Archive Storage objects in the bucket.

Default value:

None

callback_data

void *

Yes

Explanation:

Pointer to the custom callback data.

Restrictions:

None

Value range:

None

Default value:

None

Sample Code

This example obtains the direct reading configuration of Archive Storage objects in a bucket.
#include "eSDKOBS.h"
#include <stdio.h>
#include <string.h>
// The response callback function. The content of properties in the callback can be recorded in callback_data (custom callback data).
obs_status response_properties_callback(const obs_response_properties *properties, void *callback_data);
// The callback function for the completed response. The content of obs_status and obs_error_details in the callback can be recorded in callback_data (custom callback data).
void response_complete_callback(obs_status status, const obs_error_details *error, void *callback_data);
// Callback function for obtaining the direct reading configuration of a bucket
obs_status get_direct_cold_access_callback(const char *enabled, void *callback_data);
typedef struct DirectColdAccessInfo
{
    char enabled[64];
    obs_status ret_status;
}DirectColdAccessInfo;
int main()
{
    // The following example shows how to use get_bucket_direct_cold_access to obtain the direct reading configuration of Archive Storage objects in a bucket.
    // Call the obs_initialize method at the program entry to initialize global resources such as the network and memory.
    obs_initialize(OBS_INIT_ALL);
    obs_options options;
    // Create and initialize options, including the access domain name (host_name), access keys (access_key_id and access_key_secret), bucket name (bucket_name), and bucket storage class (storage_class).
    init_obs_options(&options);
    // Enter the endpoint corresponding to the bucket for host_name. CN-Hong Kong is used here as an example. Replace it with the one currently in use.
    options.bucket_options.host_name = "obs.ap-southeast-1.myhuaweicloud.com";
    // Hard-coded or plaintext AK and SK are risky. For security purposes, encrypt your AK and SK and store them in the configuration file or environment variables.
    // In this example, the AK and SK are stored in environment variables for identity authentication. Before running the code in this example, configure local environment variables ACCESS_KEY_ID and SECRET_ACCESS_KEY.
    options.bucket_options.access_key = getenv("ACCESS_KEY_ID");
    options.bucket_options.secret_access_key = getenv("SECRET_ACCESS_KEY");
    // Specify the bucket name, for example, example-bucket-name.
    char * bucketName = "example-bucket-name";
    options.bucket_options.bucket_name = bucketName;
    obs_response_handler response_handler = { &response_properties_callback, &response_complete_callback };
    // Set the response callback function.
    obs_get_bucket_direct_cold_access_handler get_direct_cold_access_handler =
    {
        response_handler,
        &get_direct_cold_access_callback
    };
    // Create callback data.
    DirectColdAccessInfo direct_cold_access_info;
    memset(&direct_cold_access_info, 0, sizeof(DirectColdAccessInfo));
    direct_cold_access_info.ret_status = OBS_STATUS_BUTT;
    // Obtain the direct reading configuration of a bucket.
    get_bucket_direct_cold_access(&options, &get_direct_cold_access_handler, &direct_cold_access_info);
    if (OBS_STATUS_OK == direct_cold_access_info.ret_status) {
        printf("get bucket direct cold access successfully. enabled: %s\n", direct_cold_access_info.enabled);
    }
    else
    {
        printf("get bucket direct cold access failed(%s).\n", obs_get_status_name(direct_cold_access_info.ret_status));
    }
    // Release the allocated global resources.
    obs_deinitialize();
}
obs_status get_direct_cold_access_callback(const char *enabled, void *callback_data)
{
    DirectColdAccessInfo *info = (DirectColdAccessInfo *)callback_data;
    if (enabled) {
        strncpy(info->enabled, enabled, sizeof(info->enabled) - 1);
        info->enabled[sizeof(info->enabled) - 1] = '\0';
    } else {
        info->enabled[0] = '\0';
    }
    return OBS_STATUS_OK;
}
// The response callback function. The content of properties in the callback can be recorded in callback_data (custom callback data).
obs_status response_properties_callback(const obs_response_properties *properties, void *callback_data)
{
    if (properties == NULL)
    {
        printf("error! obs_response_properties is null!");
        return OBS_STATUS_OK;
    }
    // Print the response.
#define print_nonnull(name, field)                                 \
    do {                                                           \
        if (properties-> field) {                                  \
            printf("%s: %s\n", name, properties->field);          \
        }                                                          \
    } while (0)
    print_nonnull("request_id", request_id);
    print_nonnull("request_id2", request_id2);
    print_nonnull("content_type", content_type);
    if (properties->content_length) {
        printf("content_length: %llu\n", properties->content_length);
    }
    print_nonnull("server", server);
    print_nonnull("ETag", etag);
    print_nonnull("version_id", version_id);
    return OBS_STATUS_OK;
}
// The callback function for the completed response. The content of obs_status and obs_error_details in the callback can be recorded in callback_data (custom callback data).
void response_complete_callback(obs_status status, const obs_error_details *error, void *callback_data)
{
    if (callback_data) {
        DirectColdAccessInfo *info = (DirectColdAccessInfo *)callback_data;
        info->ret_status = status;
    }
    else {
        printf("Callback_data is NULL");
    }
    if (error && error->message) {
        printf("Error Message: \n   %s\n", error->message);
    }
    if (error && error->resource) {
        printf("Error Resource: \n  %s\n", error->resource);
    }
    if (error && error->further_details) {
        printf("Error further_details: \n   %s\n", error->further_details);
    }
    if (error && error->extra_details_count) {
        int i;
        for (i = 0; i < error->extra_details_count; i++) {
            printf("Error Extra Detail(%d):\n   %s:%s\n", i, error->extra_details[i].name,
                error->extra_details[i].value);
        }
    }
    if (error && error->error_headers_count) {
        int i;
        for (i = 0; i < error->error_headers_count; i++) {
            const char *errorHeader = error->error_headers[i];
            printf("Error Headers(%d):\n    %s\n", i, errorHeader == NULL ? "NULL Header" : errorHeader);
        }
    }
}