最近更新时间:2024-09-05 11:30:39
KS3支持客户直接上传ZIP压缩包,通过KS3的在线解压功能,上传后的压缩文件可实现自动解压。详情请参见文档:ZIP在线解压。
如下所示为设置ZIP在线解压策略示例:
public void putDecompressPolicy() {
// 初始化 KS3Client,详情请参见文档:https://docs.ksyun.com/documents/40559
Ks3Client client = initClient();
String bucketName = "<your-bucket>";
// 规则 1
BucketDecompressPolicy.Rule rule1 = new BucketDecompressPolicy.Rule();
// 规则 ID
rule1.setId("rule1");
// 规则生效的范围(object key 以该前缀开始)
rule1.setPrefix("data/prefix1/");
// 规则生效的范围(object key 以该后缀结束)
rule1.setSuffix(Arrays.asList(".zip"));
// 规则生效的事件,支持:ObjectCreated:*、ObjectCreated:Put、ObjectCreated:Post、ObjectCreated:Copy、ObjectCreated:CompleteMultipartUpload
rule1.setEvents("ObjectCreated:Put");
// 解压后的文件路径前缀
rule1.setPathPrefix("data/prefix1/decompressed/");
// 解压后的文件路径前缀替换策略,支持:JUST_PATH_PREFIX(直接使用解压后的文件路径前缀)、ADD_FILENAME(在解压后的文件路径前缀后添加上压缩包的文件名)
rule1.setPathPrefixReplaced(BucketDecompressPolicy.PathPrefixPolicy.ADD_FILENAME);
// 解压后的文件路径前缀替换策略,支持:OVERWRITE_IF_EXISTS(如果解压后的文件已存在,则覆盖)、SKIP_IF_EXISTS(如果解压后的文件已存在,则跳过)
rule1.setOverwrite(BucketDecompressPolicy.OverwritePolicy.SKIP_IF_EXISTS);
// 回调地址
rule1.setCallback("http://callback.com");
// 回调格式,支持:JSON
rule1.setCallbackFormat("json");
// 规则 2
BucketDecompressPolicy.Rule rule2 = new BucketDecompressPolicy.Rule();
rule2.setId("rule2");
rule2.setPrefix("data/prefix2/");
rule2.setSuffix(Arrays.asList(".zip"));
rule2.setEvents("ObjectCreated:*");
rule2.setPathPrefix("data/prefix2/decompressed/");
rule2.setPathPrefixReplaced(BucketDecompressPolicy.PathPrefixPolicy.JUST_PATH_PREFIX);
rule2.setOverwrite(BucketDecompressPolicy.OverwritePolicy.OVERWRITE_IF_EXISTS);
rule2.setCallback("http://callback.com");
rule2.setCallbackFormat("json");
// 解压策略
BucketDecompressPolicy decompressPolicy = new BucketDecompressPolicy();
decompressPolicy.addRule(rule1);
decompressPolicy.addRule(rule2);
// 设置解压策略
PutBucketDecompressPolicyRequest putBucketDecompressPolicyRequest = new PutBucketDecompressPolicyRequest(bucketName, decompressPolicy);
client.putBucketDecompressPolicy(putBucketDecompressPolicyRequest);
}
如下所示为获取ZIP在线解压策略示例:
public BucketDecompressPolicy getDecompressPolicy() {
// 获取解压策略
return client.getBucketDecompressPolicy(bucketName);
}
如下所示为删除ZIP在线解压策略示例:
public void deleteDecompressPolicy() {
// 删除解压策略
client.deleteBucketDecompressPolicy(bucketName);
}
纯净模式