Configuring an Online Decompression Policy (SDK for Java)
Function
OBS can automatically decompress uploaded ZIP packages and save them to a specified directory. If any ZIP package uploaded to a bucket matches the configured decompression policy, the package will be automatically decompressed to the specified directory. You can call this API to configure a ZIP file decompression policy for a bucket. For more information about online decompression, see Online Decompression.
Online decompression is not available for fusion buckets.
Restrictions
Permissions
- To configure, obtain, or delete online decompression policies, you must have the Tenant Administrator permission assigned by using role/policy-based authorization of IAM.
- Online decompression requires that you create an IAM agency to delegate OBS to access data in the bucket. The permissions the agency should assign to OBS include obs:object:PutObject, obs:object:GetObject, and obs:object:AbortMultipartUpload.
Package and file size
- A single ZIP package cannot exceed 1 GB in size.
- A single ZIP package can contain a maximum of 65,536 files.
- A single decompressed file cannot exceed 40 GB in size.
Time
- Decompressing a ZIP package takes 10 minutes at most.
Functions
- Currently, only ZIP packages are supported.
- ZIP package names cannot contain Chinese punctuation marks, special codes, or special characters such as \/:*?"<>|@#¥
- To decompress the ZIP package that contains other ZIP packages, the event type of the online decompression policy must be set to ObjectCreated:* or ObjectCreated:CompleteMultipartUpload.
- Currently, no notification will be sent to users after decompression tasks are complete.
- Currently, only deflate-compressed ZIP packages can be decompressed. Deflate is different from the compression algorithms (such as Store and Normal) provided by WinRAR.
- The total length of the decompression path plus the name of any decompressed file cannot exceed 512 characters.
- Currently, encrypted ZIP packages cannot be decompressed.
- Federated users cannot use the online decompression function. For more information about federated users, see What Are the Relationships Between a Huawei Cloud Account, HUAWEI ID, IAM User, and Federated User? and Introduction to Identity Providers.
- The mapping between OBS regions and endpoints must comply with what is listed in Regions and Endpoints.
Method
obsClient.setBucketCompressPolicy(SetBucketCompressPolicyRequest request)
Request Parameters
| Parameter | Type | Mandatory (Yes/No) | Description |
|---|---|---|---|
| request | Yes | Explanation: Request parameters for configuring the online decompression policy. For details, see Table 2. |
| Parameter | Type | Mandatory (Yes/No) | Description |
|---|---|---|---|
| bucketName | String | Yes | Explanation: Bucket name Restrictions:
Default value: None |
| compressPolicyConfiguration | Yes | Explanation: Number of policy rules. For details, see Table 3. |
| Parameter | Type | Mandatory (Yes/No) | Description |
|---|---|---|---|
| rules | List<Table 4> | Yes | Explanation: Number of policy rules. For details, see Table 4. Restrictions: For the same bucket, prefixes of different rules cannot be the same or contain each other. The same agency is recommended. Value range: 1 to 10 Default value: None |
| Parameter | Type | Mandatory (Yes/No) | Description |
|---|---|---|---|
| id | String | Yes | Explanation: Name of a decompression rule. It is the unique ID of the decompression rule configured for the current bucket, for example, event_0001. Restrictions:
Value range: The value can be up to 256 characters long. Default value: None |
| project | String | Yes | Explanation: Project ID Value range: N/A Default value: None |
| agency | String | Yes | Explanation: IAM agency name Restrictions:
Default value: None |
| events | List<String> | Yes | Explanation: Trigger event type Value range: ["ObjectCreated:*"] ["ObjectCreated:Put"] ["ObjectCreated:Post"] ["ObjectCreated:Copy"] ["ObjectCreated:CompleteMultipartUpload"] Default value: None |
| suffix | String | Yes | Explanation: Suffix defined in the rule Restrictions: Currently, only .zip is supported. Value range: .zip Default value: None |
| prefix | String | No | Explanation: Prefix defined in the rule Value range: The value can be up to 1,023 characters long. Default value: None |
| overwrite | int | Yes | Explanation: Method of processing a decompressed file if it has the same name as an existing file Value range:
Default value: None |
| decompresspath | String | No | Explanation: Path for storing decompressed files Restrictions:
Value range: The value can be up to 800 characters long. Default value: None |
| policytype | String | Yes | Explanation: Type of the decompression policy Restrictions: Currently, only decompress is supported. Value range: decompress Default value: decompress |
Responses
| Parameter | Type | Description |
|---|---|---|
| statusCode | int | Explanation: HTTP status code. Value range: A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. For more information, see Status Code. Default value: None |
| responseHeaders | Map<String, Object> | Explanation: HTTP response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. Default value: None |
Sample Code
import com.obs.services.ObsClient;
import com.obs.services.exception.ObsException;
import com.obs.services.model.compress.CompressPolicyConfiguration;
import com.obs.services.model.compress.CompressPolicyRule;
import com.obs.services.model.compress.SetBucketCompressPolicyRequest;
import java.util.Arrays;
import java.util.List;
public class SetBucketCompressPolicy {
public static void main(String[] args) {
// Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage.
// Obtain an AK/SK pair on the management console.
String ak = System.getenv("ACCESS_KEY_ID");
String sk = System.getenv("SECRET_ACCESS_KEY_ID");
// (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are not advised to use hard coding, which may result in information leakage.
// Obtain an AK/SK pair and a security token using environment variables or import them in other ways.
String securityToken = System.getenv("SECURITY_TOKEN");
// Enter the endpoint corresponding to the bucket. CN North-Beijing4 is used here as an example. Replace it with the one currently in use.
// Obtain an endpoint using environment variables or import it in other ways.
String endPoint = System.getenv("ENDPOINT");
ObsConfiguration obsConfiguration = new ObsConfiguration();
obsConfiguration.setEndPoint(endPoint);
ObsClient obsClient = new ObsClient(ak, sk, securityToken, obsConfiguration);
try {
String exampleBucket = "exampleBucket";
String ruleId = "rule-001";
String projectId = "your_project_id";
// The permissions the agency should assign to OBS include obs:object: PutObject, obs: object:GetObject and obs: object:AbortMultipartUpload.
String agency = "your_agency";
// Trigger event type
List<String> events = Arrays.asList("ObjectCreated:*");
// Suffix defined in the rule
String suffix = ".zip";
// Method of processing decompressed files with the same names as existing files
Integer overwrite = 0;
CompressPolicyRule rule = new CompressPolicyRule(ruleId, projectId, agency, events, suffix, overwrite);
// Prefix defined in the rule
rule.setPrefix("decompress/");
// Path for storing decompressed files
rule.setDecompresspath("after-decompress/");
// Type of the file decompression policy. Currently, only decompress is supported.
rule.setPolicytype("decompress");
List<CompressPolicyRule> rules = Arrays.asList(rule);
CompressPolicyConfiguration config = new CompressPolicyConfiguration(rules);
SetBucketCompressPolicyRequest setRequest =
new SetBucketCompressPolicyRequest(exampleBucket, config);
obsClient.setBucketCompressPolicy(setRequest);
System.out.println("SetBucketCompressPolicy successfully");
} catch (ObsException e) {
System.out.println("SetBucketCompressPolicy failed");
// Request failed. Print the HTTP status code.
System.out.println("HTTP Code:" + e.getResponseCode());
// Request failed. Print the server-side error code.
System.out.println("Error Code:" + e.getErrorCode());
// Request failed. Print the error details.
System.out.println("Error Message:" + e.getErrorMessage());
// Request failed. Print the request ID.
System.out.println("Request ID:" + e.getErrorRequestId());
System.out.println("Host ID:" + e.getErrorHostId());
e.printStackTrace();
} catch (Exception e) {
System.out.println("SetBucketCompressPolicy failed");
// Print other error information.
e.printStackTrace();
}
}
} Helpful Links
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot