Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support range params in the policy #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jackcipher
Copy link

@jackcipher jackcipher commented Jun 26, 2024

Add support for content-length-range in CreateBrowserBasedSignature

Background

The current implementation of CreateBrowserBasedSignature doesn't support specifying upload size limits in the policy. The content-length-range condition is a critical feature for controlling the size of uploaded objects, but it cannot be added directly as a map[string]string using the existing method.

Proposal

This pull request implements support for the content-length-range condition as described in the OBS API documentation:
https://support.huaweicloud.com/api-obs/obs_04_0012.html

Changes

  1. Added a new ConditionRange struct to represent range conditions:
type ConditionRange struct {
    RangeName string
    Lower     int64
    Upper     int64
}
  1. Modified the CreateBrowserBasedSignatureInput struct to include a slice of ConditionRange:
type CreateBrowserBasedSignatureInput struct {
    // ... existing fields
    RangeParams []ConditionRange
}

Usage

Users can now specify upload size limits when calling CreateBrowserBasedSignature:

input := &CreateBrowserBasedSignatureInput{
    Bucket:     "your-bucket",
    Key:        "your-key",
    Expires:    300,
    FormParams: map[string]string{"acl": "public-read"},
    RangeParams: []ConditionRange{
        {
            RangeName: "content-length-range",
            Lower:     1048576,  // 1MB
            Upper:     10485760, // 10MB
        },
    },
}

output, err := obsClient.CreateBrowserBasedSignature(input)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant