.Net
Java-Maven配置
//ECS SDK Java maven
<dependency>
<groupId>com.emc.ecs</groupId>
<artifactId>object-client</artifactId>
<version>3.1.3</version>
</dependency>
//Gateway SDK Java maven
<dependency>
<groupId>com.emphant.gateway</groupId>
<artifactId>ecs-gateway-client</artifactId>
<version>1.0.3</version>
</dependency>
//AWS S3 SDK Java Maven(AWS S3 SDK,功能上兼容ECS)
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>1.9.1</version>
</dependency>
详情参见:Java-EcsDemo
若存在日志slf4j-log4j12
冲突的问题,解决如下:
日志冲突问题解决:
<dependency>
<groupId>com.emc.ecs</groupId>
<artifactId>object-client</artifactId>
<version>3.1.3</version>
<exclusions>
<exclusion>
<artifactId>slf4j-log4j12</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
提供一个ECS的java工具类
Java
生命周期
配置过期策略,支持增删改查,注意,若当前Bucket策略空,直接删除会报错。.Net版本
查询
private LifecycleConfiguration GetEcsRules() {
// Retrieve current configuration
GetLifecycleConfigurationRequest getRequest = new GetLifecycleConfigurationRequest {
BucketName = _bucketName };
var response = _s3Client.GetLifecycleConfiguration(getRequest);
return (response != null && response.Configuration != null) ? response.Configuration : null;
}
删除
private void DeleteEcsRules() {
// Delete current configuration
DeleteLifecycleConfigurationRequest deleteRequest = new DeleteLifecycleConfigurationRequest {
BucketName = _bucketName };
_s3Client.DeleteLifecycleConfiguration(deleteRequest);
}
更新
private void UpdateEcsRules(LifecycleConfiguration lcConfig_New = null) {
LifecycleRuleExpiration lcRuleExpiration = new LifecycleRuleExpiration() {
Days = _expireDay, };
LifecycleRule lcRule_1 = new LifecycleRule() {
Expiration = lcRuleExpiration,
Prefix = DateTime.Now.AddDays(-2).ToString(_prefix_format),
Status = LifecycleRuleStatus.Enabled,
};
LifecycleConfiguration lcConfig = new LifecycleConfiguration();
lcConfig.Rules.Add(lcRule_1);
PutLifecycleConfigurationRequest request = new PutLifecycleConfigurationRequest() {
BucketName = _bucketName, Configuration = lcConfig,
};
_s3Client.PutLifecycleConfiguration(request);
}