✨ added the image backup API
This commit is contained in:
@@ -419,3 +419,45 @@ func (a *AliOSS) PresignedURL(ctx context.Context, bucketName, objectKey string,
|
||||
|
||||
return presignedResult.URL, nil
|
||||
}
|
||||
|
||||
// PutBucketReplication 配置跨区域复制规则
|
||||
func (a *AliOSS) PutBucketReplication(ctx context.Context, originBucketName, targetBucketName, targetBucketRegion string) (string, error) {
|
||||
request := &oss.PutBucketReplicationRequest{
|
||||
Bucket: oss.Ptr(originBucketName), // 存储空间名称
|
||||
ReplicationConfiguration: &oss.ReplicationConfiguration{
|
||||
Rules: []oss.ReplicationRule{
|
||||
{
|
||||
RTC: &oss.ReplicationTimeControl{
|
||||
Status: oss.Ptr("enabled"), // 在配置跨区域复制规则时,开启数据复制时间控制(RTC)功能
|
||||
},
|
||||
Destination: &oss.ReplicationDestination{
|
||||
Bucket: oss.Ptr(targetBucketName), // 目标存储空间名称
|
||||
Location: oss.Ptr(targetBucketRegion), // 目标存储区域
|
||||
TransferType: oss.TransferTypeOssAcc, // 传输类型
|
||||
},
|
||||
HistoricalObjectReplication: oss.HistoricalObjectReplicationEnabled, // 开启历史数据复制功能
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
result, err := a.client.PutBucketReplication(ctx, request)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to put bucket replication, error: %v", err)
|
||||
}
|
||||
return *result.ReplicationRuleId, nil
|
||||
}
|
||||
|
||||
// DeleteBucketReplication 删除跨区域复制规则
|
||||
func (a *AliOSS) DeleteBucketReplication(ctx context.Context, bucketName string, ruleId string) error {
|
||||
request := &oss.DeleteBucketReplicationRequest{
|
||||
Bucket: oss.Ptr(bucketName), // 存储空间名称
|
||||
ReplicationRules: &oss.ReplicationRules{
|
||||
IDs: []string{ruleId}, // 复制规则ID列表
|
||||
},
|
||||
}
|
||||
_, err := a.client.DeleteBucketReplication(ctx, request)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to delete bucket replication, error: %v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@@ -77,4 +77,6 @@ type Service interface {
|
||||
DeleteObject(ctx context.Context, bucketName, objectName string) (int, error)
|
||||
RenameObject(ctx context.Context, destBucketName, destObjectName, srcObjectName, srcBucketName string) (int, error)
|
||||
PresignedURL(ctx context.Context, bucketName, objectKey string, expires time.Duration) (string, error)
|
||||
PutBucketReplication(ctx context.Context, originBucketName, targetBucketName, targetBucketRegion string) (string, error)
|
||||
DeleteBucketReplication(ctx context.Context, bucketName string, ruleId string) error
|
||||
}
|
||||
|
Reference in New Issue
Block a user