更新时间:2026-07-10 GMT+08:00
分享

获取在线解压策略

功能介绍

桶拥有者或拥有获取在线解压策略权限的用户可通过本接口查询指定桶的文件解压策略。如果策略存在,则返回成功,status code返回值为200。

接口约束

  • 您必须是桶拥有者或拥有获取在线解压策略的权限,才能调用本接口,建议使用IAM或桶策略进行授权。了解更多OBS授权方式请参见OBS不同权限控制方式的区别
  • OBS支持的Region与Endpoint的对应关系,详细信息请参见地区与终端节点

方法定义

func (obsClient ObsClient) GetBucketDecompression(input *GetBucketDecompressionInput, extensions ...extensionOptions) (output *GetBucketDecompressionOutput, err error)

请求参数说明

表1 请求参数列表

参数名称

参数类型

是否必选

描述

input

*GetBucketDecompressionInput

必选

参数解释:

获取在线解压策略请求参数,详见GetBucketDecompressionInput

extensions

extensionOptions

可选

参数解释:

桶相关扩展信息。通过调用拓展配置项为对应请求配置额外的拓展请求头,详情参考extensionOptions

表2 GetBucketDecompressionInput

参数名称

参数类型

是否必选

描述

Bucket

string

必选

参数解释

桶名。

约束限制:

  • 桶的名字需全局唯一,不能与已有的任何桶名称重复,包括其他用户创建的桶。
  • 桶命名规则如下:
    • 3~63个字符,数字或字母开头,支持小写字母、数字、“-”、“.”。
    • 禁止使用IP地址。
    • 禁止以“-”或“.”开头及结尾。
    • 禁止两个“.”相邻(如:“my..bucket”)。
    • 禁止“.”和“-”相邻(如:“my-.bucket”和“my.-bucket”)。
  • 同一用户在同一个区域多次创建同名桶不会报错,创建的桶属性以第一次请求为准。

默认取值:

返回结果说明

表3 返回结果列表

参数名称

参数类型

描述

output

*GetBucketDecompressionOutput

参数解释:

接口返回信息,详见GetBucketDecompressionOutput

err

error

参数解释:

接口返回错误信息。

表4 GetBucketDecompressionOutput

参数名称

参数类型

描述

StatusCode

int

参数解释:

HTTP状态码。

取值范围:

状态码是一组从2xx(成功)到4xx或5xx(错误)的数字代码,状态码表示了请求响应的状态。完整的状态码列表请参见状态码

默认取值:

RequestId

string

参数解释:

OBS服务端返回的请求ID。

默认取值:

ResponseHeaders

map[string][]string

参数解释:

HTTP响应头信息。

默认取值:

Rules

[]DecompressionRule

参数解释:

在线解压策略。

取值范围:

参见DecompressionRule

默认取值:

表5 DecompressionRule

参数名称

参数类型

是否必选

描述

ID

string

必选

参数解释:

解压策略名称。当前桶上配置的解压规则的唯一标识。

取值范围:

[1, 256],满足“^[a-zA-Z0-9_-]{1, 256}$”,即长度为1~256个字符。只能由大写或小写的英文字母、数字、下划线(_)和连字符(-)组成。例如:event_0001。

默认取值:

Project

string

必选

参数解释:

项目ID。

默认取值:

Agency

string

必选

参数解释:

委托名。客户通过委托赋予OBS服务查询用户桶内指定对象是否存在以及向用户桶内上传对象的权限。

默认取值:

Events

[]string

必选

参数解释:

触发事件类型。

取值范围:

["ObjectCreated:*"]
["ObjectCreated:Put"]
["ObjectCreated:Post"]
["ObjectCreated:Copy"]
["ObjectCreated:CompleteMultipartUpload"]

Prefix

string

可选

参数解释:

匹配规则前缀。

取值范围:

[0, 1023]

Suffix

string

必选

参数解释:

匹配规则后缀。

取值范围:

固定值:.zip

Overwrite

int

必选

参数解释:

解压后同名文件的处理方式。

取值范围:

  • 0:不覆盖跳过
  • 1:不覆盖,以文件的CRC32值重命名
  • 2:覆盖。

DecompressPath

string

可选

参数解释:

文件解压后存放的路径,不为空时必须以“/”结尾,且不能以“/”开头。

取值范围:

[0, 800]

PolicyType

string

必选

参数解释:

文件解压策略类型。

取值范围:

固定值:decompress:执行解压操作

代码示例

本示例用于获取名为examplebucket桶的在线解压策略。
package main
import (
    "fmt"
    "os"
    obs "github.com/huaweicloud/huaweicloud-sdk-go-obs/obs"
)
func main() {
    //推荐通过环境变量获取AKSK,这里也可以使用其他外部引入方式传入,如果使用硬编码可能会存在泄露风险。
    //您可以登录访问管理控制台获取访问密钥AK/SK,获取方式请参见https://support.huaweicloud.com/usermanual-ca/ca_01_0003.html。
    ak := os.Getenv("AccessKeyID")
    sk := os.Getenv("SecretAccessKey")
    // 【可选】如果使用临时AK/SK和SecurityToken访问OBS,同样建议您尽量避免使用硬编码,以降低信息泄露风险。您可以通过环境变量获取访问密钥AK/SK,也可以使用其他外部引入方式传入。
    securityToken := os.Getenv("SecurityToken")
    // endpoint填写Bucket对应的Endpoint, 这里以华北-北京四为例,其他地区请按实际情况填写。
    endPoint := "https://obs.cn-north-4.myhuaweicloud.com"
    // 创建obsClient实例
    // 如果使用临时AKSK和SecurityToken访问OBS,需要在创建实例时通过obs.WithSecurityToken方法指定securityToken值。
    obsClient, err := obs.New(ak, sk, endPoint, obs.WithSecurityToken(securityToken))
    if err != nil {
        fmt.Printf("Create obsClient error, errMsg: %s", err.Error())
    }
    input := &obs.GetBucketDecompressionInput{}
    // 指定存储桶名称
    input.Bucket = "examplebucket
    // 获取桶的在线解压策略
    output, err := obsClient.GetBucketDecompression(bucketName)
    if err == nil {
	fmt.Printf("Get bucket(%s)'s decompression policy successful!\n", bucketName)
        fmt.Printf("Decompression rules count: %d\n", len(output.Rules))
        for index, rule := range output.Rules {
            fmt.Printf("Rule[%d] - ID: %s, Prefix: %s, Suffix: %s, PolicyType: %s\n",
            index, rule.ID, rule.Prefix, rule.Suffix, rule.PolicyType)
        }
	fmt.Printf("RequestId:%s\n", output.RequestId)
	return
    }
    fmt.Printf("Get bucket(%s)'s decompression policy 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)
    }
}

相关链接

  • 关于获取在线解压策略的API说明,请参见获取在线解压策略
  • 获取在线解压策略过程中返回的错误码含义、问题原因及处理措施可参考OBS错误码
  • 获取在线解压策略相关问题请参见在线解压

相关文档