public void putBucketReplication() { //.cssg-snippet-body-start:[put-bucket-replication] CosXmlConfig config = new CosXmlConfig.Builder() .SetConnectionTimeoutMs(60000) //设置连接超时时间,单位毫秒,默认45000ms .SetReadWriteTimeoutMs(40000) //设置读写超时时间,单位毫秒,默认45000ms .IsHttps(true) //设置默认 HTTPS 请求 .SetAppid("1253653367") //设置腾讯云账户的账户标识 APPID .SetRegion("ap-guangzhou") //设置一个默认的存储桶地域 .Build(); string secretId = Environment.GetEnvironmentVariable("COS_KEY"); //云 API 密钥 SecretId string secretKey = Environment.GetEnvironmentVariable("COS_SECRET"); //云 API 密钥 SecretKey long durationSecond = 600; //每次请求签名有效时长,单位为秒 QCloudCredentialProvider qCloudCredentialProvider = new DefaultQCloudCredentialProvider(secretId, secretKey, durationSecond); CosXml cosXml = new CosXmlServer(config, qCloudCredentialProvider); string bucket = "bucket-cssg-test-dotnet-1253653367"; //格式:BucketName-APPID string ownerUin = "1278687956"; //发起者身份标示: OwnerUin string subUin = "1278687956"; //发起者身份标示: SubUin PutBucketReplicationRequest request = new PutBucketReplicationRequest(bucket); //设置 replication PutBucketReplicationRequest.RuleStruct ruleStruct = new PutBucketReplicationRequest.RuleStruct(); ruleStruct.id = "replication_01"; //用来标注具体 Rule 的名称 ruleStruct.isEnable = true; //标识 Rule 是否生效 :true, 生效; false, 不生效 ruleStruct.appid = "1253653367"; //APPID ruleStruct.region = "ap-beijing"; //目标存储桶地域信息 ruleStruct.bucket = "bucket-cssg-assist-1253653367"; //格式:BucketName-APPID ruleStruct.prefix = "34"; //前缀匹配策略 List <PutBucketReplicationRequest.RuleStruct> ruleStructs = new List <PutBucketReplicationRequest.RuleStruct>(); ruleStructs.Add(ruleStruct); request.SetReplicationConfiguration(ownerUin, subUin, ruleStructs); // 使用同步方法 try { PutBucketReplicationResult result = cosXml.PutBucketReplication(request); Console.WriteLine(result.GetResultInfo()); } catch (COSXML.CosException.CosClientException clientEx) { Console.WriteLine("CosClientException: " + clientEx); Assert.Null(clientEx); } catch (COSXML.CosException.CosServerException serverEx) { Console.WriteLine("CosServerException: " + serverEx.GetInfo()); Assert.Null(serverEx); } //.cssg-snippet-body-end }
static async Task EnableReplicationAsync() { try { ReplicationConfiguration replConfig = new ReplicationConfiguration { Role = roleArn, Rules = { new ReplicationRule { Prefix = "Tax", Status = ReplicationRuleStatus.Enabled, Destination = new ReplicationDestination { BucketArn = destinationBucketArn } } } }; PutBucketReplicationRequest putRequest = new PutBucketReplicationRequest { BucketName = sourceBucket, Configuration = replConfig }; PutBucketReplicationResponse putResponse = await s3Client.PutBucketReplicationAsync(putRequest); // Verify configuration by retrieving it. await RetrieveReplicationConfigurationAsync(s3Client); } catch (AmazonS3Exception e) { Console.WriteLine("Error encountered on server. Message:'{0}' when writing an object", e.Message); } catch (Exception e) { Console.WriteLine("Unknown encountered on server. Message:'{0}' when writing an object", e.Message); } }
public static void AsynPutBucketReplication(COSXML.CosXml cosXml, string bucket) { PutBucketReplicationRequest request = new PutBucketReplicationRequest(bucket); //设置签名有效时长 request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); //设置replication PutBucketReplicationRequest.RuleStruct ruleStruct = new PutBucketReplicationRequest.RuleStruct(); ruleStruct.appid = ""; ruleStruct.bucket = ""; ruleStruct.region = ""; ruleStruct.isEnable = true; ruleStruct.storageClass = ""; ruleStruct.id = ""; ruleStruct.prefix = ""; List <PutBucketReplicationRequest.RuleStruct> ruleStructs = new List <PutBucketReplicationRequest.RuleStruct>(); ruleStructs.Add(ruleStruct); request.SetReplicationConfiguration("2832742109", "2832742109", ruleStructs); ///执行请求 cosXml.PutBucketReplication(request, delegate(CosResult cosResult) { PutBucketReplicationResult result = cosResult as PutBucketReplicationResult; Console.WriteLine(result.GetResultInfo()); }, delegate(CosClientException clientEx, CosServerException serverEx) { if (clientEx != null) { QLog.D("XIAO", clientEx.Message); Console.WriteLine("CosClientException: " + clientEx.Message); } if (serverEx != null) { QLog.D("XIAO", serverEx.Message); Console.WriteLine("CosServerException: " + serverEx.GetInfo()); } }); }
/// <summary> /// This method adds replication rules to the Amazon S3 source bucket. /// </summary> /// <param name="client">The initialized Amazon S3 client object used to /// create and add the replication configuration to the source bucket.</param> /// <param name="sourceBucket">A string representing the name of the /// source Amazon S3 bucket.</param> /// <param name="destinationBucketArn">The ARN of the destination Amazon /// S3 bucket.</param> /// <param name="roleArn">The ARN of the role which will be used to /// replicate the contents of the source Amazon S3 bucket.</param> public static async Task EnableReplicationAsync( IAmazonS3 client, string sourceBucket, string destinationBucketArn, string roleArn) { try { var replConfig = new ReplicationConfiguration { Role = roleArn, Rules = { new ReplicationRule { Filter = new ReplicationRuleFilter{ Prefix = "Tax" }, Status = ReplicationRuleStatus.Enabled, Destination = new ReplicationDestination { BucketArn = destinationBucketArn, }, }, }, }; var request = new PutBucketReplicationRequest { BucketName = sourceBucket, Configuration = replConfig, }; var response = await client.PutBucketReplicationAsync(request); } catch (AmazonS3Exception ex) { Console.WriteLine($"Error: {ex.Message}"); } }
private void PutBucketReplication() { try { PutBucketReplicationRequest request = new PutBucketReplicationRequest(bucket); //设置replication PutBucketReplicationRequest.RuleStruct ruleStruct = new PutBucketReplicationRequest.RuleStruct(); ruleStruct.appid = QCloudServer.Instance().appid; ruleStruct.bucket = QCloudServer.Instance().bucketVersioning; ruleStruct.region = QCloudServer.Instance().regionForBucketVersioning; ruleStruct.isEnable = true; ruleStruct.storageClass = "STANDARD"; ruleStruct.id = "replication1"; ruleStruct.prefix = "dir/"; request.SetReplicationConfiguration("2832742109", "2832742109", new List <PutBucketReplicationRequest.RuleStruct>() { ruleStruct }); //执行请求 PutBucketReplicationResult result = cosXml.PutBucketReplication(request); Assert.AreEqual(result.httpCode, 200); } catch (COSXML.CosException.CosClientException clientEx) { Console.WriteLine("CosClientException: " + clientEx.Message); Assert.Fail(); } catch (COSXML.CosException.CosServerException serverEx) { Console.WriteLine("CosServerException: " + serverEx.GetInfo()); Assert.Fail(); } }
/// 设置存储桶跨地域复制规则 public void PutBucketReplication() { //.cssg-snippet-body-start:[put-bucket-replication] string bucket = "examplebucket-1250000000"; //格式:BucketName-APPID string ownerUin = "100000000001"; //发起者身份标示: OwnerUin string subUin = "100000000001"; //发起者身份标示: SubUin PutBucketReplicationRequest request = new PutBucketReplicationRequest(bucket); //设置 replication PutBucketReplicationRequest.RuleStruct ruleStruct = new PutBucketReplicationRequest.RuleStruct(); ruleStruct.id = "replication_01"; //用来标注具体 Rule 的名称 ruleStruct.isEnable = true; //标识 Rule 是否生效 :true, 生效; false, 不生效 ruleStruct.appid = "1250000000"; //APPID ruleStruct.region = "ap-beijing"; //目标存储桶地域信息 ruleStruct.bucket = "destinationbucket-1250000000"; //格式:BucketName-APPID ruleStruct.prefix = "34"; //前缀匹配策略 List <PutBucketReplicationRequest.RuleStruct> ruleStructs = new List <PutBucketReplicationRequest.RuleStruct>(); ruleStructs.Add(ruleStruct); request.SetReplicationConfiguration(ownerUin, subUin, ruleStructs); try { PutBucketReplicationResult result = cosXml.PutBucketReplication(request); Console.WriteLine(result.GetResultInfo()); } catch (COSXML.CosException.CosClientException clientEx) { Console.WriteLine("CosClientException: " + clientEx); } catch (COSXML.CosException.CosServerException serverEx) { Console.WriteLine("CosServerException: " + serverEx.GetInfo()); } //.cssg-snippet-body-end }
public void PutBucketReplication(PutBucketReplicationRequest request, Callback.OnSuccessCallback <CosResult> successCallback, Callback.OnFailedCallback failCallback) { Schedue(request, new PutBucketReplicationResult(), successCallback, failCallback); }
public PutBucketReplicationResult PutBucketReplication(PutBucketReplicationRequest request) { return((Model.Bucket.PutBucketReplicationResult)Excute(request, new Model.Bucket.PutBucketReplicationResult())); }
public Task <PutBucketReplicationResponse> PutBucketReplicationAsync(PutBucketReplicationRequest request, CancellationToken cancellationToken = default) { throw new NotImplementedException(); }
public void PutBucketReplicationAsync(PutBucketReplicationRequest request, AmazonServiceCallback <PutBucketReplicationRequest, PutBucketReplicationResponse> callback, AsyncOptions options = null) { throw new System.NotImplementedException(); }