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

Obtaining an Online Decompression Policy (SDK for C)

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

Function

This API is used to obtain the online decompression policy of a specified bucket, including the detailed configuration of all decompression rules.

Restrictions

Method

void get_bucket_compress_policy(const obs_options *options,
    obs_get_bucket_compress_policy_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

Table 2*

Yes

Explanation:

Callback structure, including the response callback, end callback, and callback for obtaining the online decompression policy.

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_compress_policy_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_compress_policy_callback

Table 3*

Yes

Explanation:

Pointer to the callback function of the bucket encryption configuration. You can record the content of encryption_config in callback_data in this callback.

Restrictions:

None

Value range:

None

Default value:

None

Table 3 obs_get_bucket_compress_policy_callback

Parameter

Type

Mandatory (Yes/No)

Description

compress_policy_rules

Table 4*

Yes

Explanation:

Array of online decompression rules.

Restrictions:

None

Value range:

None

Default value:

None

rule_number

unsigned int

Yes

Explanation:

Number of rules.

Restrictions:

A maximum of 10 rules are supported.

Value range:

1 to 10

Default value:

None

callback_data

void *

Yes

Explanation:

Pointer to the custom callback data.

Restrictions:

None

Value range:

None

Default value:

None

Table 4 obs_compress_policy_rule

Parameter

Type

Mandatory (Yes/No)

Description

id

char *

Yes

Explanation:

Rule ID, which uniquely identifies a decompression rule.

Restrictions:

Only letters, digits, underscores (_), and hyphens (-) are allowed.

Value range:

The value can contain 1 to 256 characters and must match the regular expression ^[a-zA-Z0-9_-]{1,256}$.

Default value:

None

project

char *

Yes

Explanation:

Project ID, which identifies the project to which the decompression task belongs.

Restrictions:

None

Value range:

None

Default value:

None

agency

char *

Yes

Explanation:

Name of the agency, which is used to authorize OBS to perform decompression operations.

Restrictions:

None

Value range:

None

Default value:

None

events

char **

Yes

Explanation:

Event type array, which specifies the events that trigger decompression.

Restrictions:

None

Value range:

Supported event types include ObjectCreated:*, ObjectCreated:Put, and more.

Default value:

None

events_number

unsigned int

Yes

Explanation:

Number of event types.

Restrictions:

The number of event types must match the number of elements in the events array.

Value range:

A value greater than 0

Default value:

None

prefix

char *

No

Explanation:

Object name prefix filter. Decompression is triggered only for objects with the specified prefix.

Restrictions:

None

Value range:

None

Default value:

None, indicating that there is no limit on the prefix.

suffix

char *

Yes

Explanation:

Object name suffix filter.

Restrictions:

None

Value range:

The value is fixed at .zip.

Default value:

None

overwrite

int

Yes

Explanation:

Method of processing decompressed files with the same names as existing files.

Restrictions:

None

Value range:

0: Skip. 1: Rename the file with the CRC32 value. 2: Overwrite the existing file.

Default value:

None

decompress_path

char *

No

Explanation:

Path for storing the decompressed files.

Restrictions:

If the value is not empty, it must end with a slash (/).

Value range:

None

Default value:

None, indicating that the package is decompressed to the directory where the package is located.

policy_type

char *

Yes

Explanation:

Policy type.

Restrictions:

None

Value range:

The value is fixed at decompress.

Default value:

None

Sample Code

This example obtains the online decompression policy of a bucket.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "eSDKOBS.h"
#include <stdio.h>
#include <string.h>
obs_status response_properties_callback(const obs_response_properties *properties, void *callback_data);
void response_complete_callback(obs_status status, const obs_error_details *error, void *callback_data);
typedef struct CompressPolicyResult
{
    obs_compress_policy_rule *rules;
    unsigned int rule_count;
    obs_status ret_status;
} CompressPolicyResult;
obs_status get_compress_policy_callback(obs_compress_policy_rule *rules_return,
                                         unsigned int rule_number, void *callback_data)
{
    CompressPolicyResult *result = (CompressPolicyResult *)callback_data;
    result->rules = rules_return;
    result->rule_count = rule_number;
    return OBS_STATUS_OK;
}
int main()
{
    obs_initialize(OBS_INIT_ALL);
    obs_options options;
    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");
    options.bucket_options.bucket_name = "example-bucket-name";
    obs_get_bucket_compress_policy_handler handler = {0};
    handler.response_handler.properties_callback = &response_properties_callback;
    handler.response_handler.complete_callback = &response_complete_callback;
    handler.get_bucket_compress_policy_callback = &get_compress_policy_callback;
    CompressPolicyResult result;
    memset(&result, 0, sizeof(CompressPolicyResult));
    result.ret_status = OBS_STATUS_BUTT;
    get_bucket_compress_policy(&options, &handler, &result);
    if (OBS_STATUS_OK == result.ret_status) {
        printf("get bucket compress policy successfully.\n");
        printf("rule count: %u\n", result.rule_count);
        for (unsigned int i = 0; i < result.rule_count; i++) {
            printf("rule[%u]: id=%s, suffix=%s, overwrite=%d, decompress_path=%s, policy_type=%s\n",
                   i,
                   result.rules[i].id ? result.rules[i].id : "(null)",
                   result.rules[i].suffix ? result.rules[i].suffix : "(null)",
                   result.rules[i].overwrite,
                   result.rules[i].decompress_path ? result.rules[i].decompress_path : "(null)",
                   result.rules[i].policy_type ? result.rules[i].policy_type : "(null)");
        }
    } else {
        printf("get bucket compress policy failed(%s).\n", obs_get_status_name(result.ret_status));
    }
    obs_deinitialize();
}
obs_status response_properties_callback(const obs_response_properties *properties, void *callback_data)
{
    (void)properties; (void)callback_data;
    return OBS_STATUS_OK;
}
void response_complete_callback(obs_status status, const obs_error_details *error, void *callback_data)
{
    if (callback_data) {
        CompressPolicyResult *result = (CompressPolicyResult *)callback_data;
        result->ret_status = status;
    }
    if (error && error->message) { printf("Error: %s\n", error->message); }
}