Help Center/ Object Storage Service/ SDK Reference/ C/ Bucket APIs (SDK for C)/ Online Decompression (SDK for C)/ Configuring an Online Decompression Policy (SDK for C)
Updated on 2026-08-03 GMT+08:00

Configuring 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 configure an online decompression policy for a specified bucket. With an online decompression policy, a ZIP package is automatically decompressed to a specified path when it is uploaded to a bucket. This enables automatic data processing.

Restrictions

Method

void set_bucket_compress_policy(const obs_options *options,
    obs_compress_policy_rule *compress_policy_rules,
    unsigned int rule_number,
    obs_response_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

compress_policy_rules

Table 2*

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

handler

obs_response_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_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 configures an online decompression policy for a bucket.

#include "eSDKOBS.h"
#include <stdio.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);
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";
    // Configure an online decompression rule.
    obs_compress_policy_rule rule = {0};
    rule.id = "decompress-rule-001";
    rule.project = "your-project-id";
    rule.agency = "your-agency-name";
    const char* events[] = {"ObjectCreated:*"};
    rule.events = (char**)events;
    rule.events_number = 1;
    rule.prefix = "zip-files/";
    rule.suffix = ".zip";
    rule.overwrite = 0;
    rule.decompress_path = "unzipped/";
    rule.policy_type = "decompress";
    obs_response_handler response_handler = {&response_properties_callback, &response_complete_callback};
    obs_status ret_status = OBS_STATUS_BUTT;
    set_bucket_compress_policy(&options, &rule, 1, &response_handler, &ret_status);
    if (OBS_STATUS_OK == ret_status) {
        printf("set bucket compress policy successfully.\n");
    } else {
        printf("set bucket compress policy failed(%s).\n", obs_get_status_name(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) { *(obs_status*)callback_data = status; }
    if (error && error->message) { printf("Error: %s\n", error->message); }
}