public static void AsynGetBucketVersioning(COSXML.CosXml cosXml, string bucket) { GetBucketVersioningRequest request = new GetBucketVersioningRequest(bucket); //设置签名有效时长 request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); //执行请求 cosXml.GetBucketVersioning(request, delegate(CosResult cosResult) { GetBucketVersioningResult result = cosResult as GetBucketVersioningResult; 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()); } }); }
private void GetBucketVersioning() { try { GetBucketVersioningRequest request = new GetBucketVersioningRequest(bucket); //执行请求 GetBucketVersioningResult result = cosXml.GetBucketVersioning(request); var versioning = result.versioningConfiguration; // Console.WriteLine(result.GetResultInfo()); Assert.IsNotEmpty((result.GetResultInfo())); Assert.AreEqual(result.httpCode, 200); Assert.NotNull(versioning); Assert.Contains(versioning.status, new List <String>() { "Enabled", "Suspended" }); } 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 Task <GetBucketVersioningResponse> GetBucketVersioningAsync(string bucketName, Action <GetBucketVersioningRequest>?config = null, CancellationToken token = default) { GetBucketVersioningRequest request = new GetBucketVersioningRequest(bucketName); config?.Invoke(request); return(_bucketOperations.GetBucketVersioningAsync(request, token)); }
public static void Main(string[] args) { // create the AWS S3 client AmazonS3Client s3 = AWSS3Factory.getS3Client(); System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true); GetBucketVersioningRequest gvr = new GetBucketVersioningRequest() { BucketName = AWSS3Factory.S3_BUCKET }; Console.WriteLine(s3.GetBucketVersioning(gvr).VersioningConfig.Status); bool moreRecords = true; string nextMarker = string.Empty; while (moreRecords) { ListVersionsRequest request = new ListVersionsRequest() { BucketName = AWSS3Factory.S3_BUCKET, }; //if (nextMarker.Length > 0) //request.KeyMarker = nextMarker; request.VersionIdMarker = "1472739256446"; ListVersionsResponse response = new ListVersionsResponse(); response = s3.ListVersions(request); foreach (S3ObjectVersion key in response.Versions) { Console.WriteLine(key.Key); } Console.WriteLine(string.Format("Next Marker: {0} Version Count: {1}", response.NextKeyMarker, response.Versions.Count.ToString())); if (response.IsTruncated) { nextMarker = response.NextKeyMarker; } else { moreRecords = false; } } // print out object key/value for validation //Console.WriteLine(string.Format("Copied object {0}/{1} to {2}/{3}", AWSS3Factory.S3_BUCKET, key_source, AWSS3Factory.S3_BUCKET, key_target)); Console.ReadLine(); }
public async Task <string> RetrieveBucketVersioningConfiguration(AmazonS3Client client) { GetBucketVersioningRequest request = new GetBucketVersioningRequest { BucketName = s3config.bucketName }; GetBucketVersioningResponse response = await client.GetBucketVersioningAsync(request); return(response.VersioningConfig.Status); }
private static void GetBucketVersioning() { try { GetBucketVersioningRequest request = new GetBucketVersioningRequest() { BucketName = bucketName }; GetBucketVersioningResponse response = client.GetBucketVersioning(request); Console.WriteLine("GetBucketVersioning response: {0}", response.StatusCode); Console.WriteLine("GetBucketVersioning version status: {0}", response.Configuration.Status); } catch (ObsException ex) { Console.WriteLine("Exception errorcode: {0}, when get bucket versioning", ex.ErrorCode); Console.WriteLine("Exception errormessage: {0}", ex.ErrorMessage); } }
public void getBucketVersioning() { //.cssg-snippet-body-start:[get-bucket-versioning] 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 GetBucketVersioningRequest request = new GetBucketVersioningRequest(bucket); // 使用同步方法 try { GetBucketVersioningResult result = cosXml.GetBucketVersioning(request); // 存储桶的生命周期配置 VersioningConfiguration conf = result.versioningConfiguration; } 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 void ReadBucketVersioning() { string bucket = Common.InputString("Bucket:", null, false); GetBucketVersioningRequest request = new GetBucketVersioningRequest(); request.BucketName = bucket; GetBucketVersioningResponse response = _S3Client.GetBucketVersioningAsync(request).Result; if (response != null) { Console.WriteLine("Success"); Console.WriteLine(" MFA delete : " + response.VersioningConfig.EnableMfaDelete.ToString()); Console.WriteLine(" Versioning : " + response.VersioningConfig.Status.Value); } else { Console.WriteLine("Failed"); } }
/// 获取存储桶多版本状态 public void GetBucketVersioning() { //.cssg-snippet-body-start:[get-bucket-versioning] string bucket = "examplebucket-1250000000"; //格式:BucketName-APPID GetBucketVersioningRequest request = new GetBucketVersioningRequest(bucket); try { GetBucketVersioningResult result = cosXml.GetBucketVersioning(request); // 存储桶的生命周期配置 VersioningConfiguration conf = result.versioningConfiguration; } catch (COSXML.CosException.CosClientException clientEx) { Console.WriteLine("CosClientException: " + clientEx); } catch (COSXML.CosException.CosServerException serverEx) { Console.WriteLine("CosServerException: " + serverEx.GetInfo()); } //.cssg-snippet-body-end }
public static void GetBucketVersioning(COSXML.CosXml cosXml, string bucket) { try { GetBucketVersioningRequest request = new GetBucketVersioningRequest(bucket); //设置签名有效时长 request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); //执行请求 GetBucketVersioningResult result = cosXml.GetBucketVersioning(request); Console.WriteLine(result.GetResultInfo()); } catch (COSXML.CosException.CosClientException clientEx) { QLog.D("XIAO", clientEx.Message); Console.WriteLine("CosClientException: " + clientEx.Message); } catch (COSXML.CosException.CosServerException serverEx) { QLog.D("XIAO", serverEx.Message); Console.WriteLine("CosServerException: " + serverEx.GetInfo()); } }
public static void Main(string[] args) { // create the AWS S3 client AmazonS3Client s3 = AWSS3Factory.getS3Client(); String bucketName = String.Join("-", AWSS3Factory.S3_BUCKET, DateTime.Now.ToString("yyyyMMddHHmmss")); //********************// // 1. Create a bucket // //********************// Console.Write(string.Format(" [*] Creating bucket '{0}'... ", bucketName)); PutBucketResponse pbRes = s3.PutBucket(bucketName); if (pbRes.HttpStatusCode != System.Net.HttpStatusCode.OK) { Console.WriteLine("fail"); Console.ReadLine(); System.Environment.Exit(1); } Console.WriteLine("done"); //*******************************************// // 2. Get current bucket versioning status // //*******************************************// Console.Write(string.Format(" [*] Getting bucket versioning status for bucket '{0}'... ", bucketName)); GetBucketVersioningRequest gvr = new GetBucketVersioningRequest() { BucketName = bucketName }; GetBucketVersioningResponse gvrResponse = s3.GetBucketVersioning(gvr); Console.Write(string.Format("status: {0}", gvrResponse.VersioningConfig.Status)); //*******************************************// // 3. Enable object versioning on the bucket // //*******************************************// // enabled versioning if not yet enabled if (gvrResponse.VersioningConfig.Status != VersionStatus.Enabled) { Console.Write(string.Format(" [*] Enabling bucket versioning for bucket '{0}'... ", bucketName)); PutBucketVersioningRequest pvr = new PutBucketVersioningRequest() { BucketName = bucketName, VersioningConfig = new S3BucketVersioningConfig() { Status = VersionStatus.Enabled } }; PutBucketVersioningResponse pvrResponse = s3.PutBucketVersioning(pvr); if (pvrResponse.HttpStatusCode != System.Net.HttpStatusCode.OK) { Console.WriteLine("fail"); Console.ReadLine(); System.Environment.Exit(1); } Console.WriteLine("done"); } //***********************************************************************// // 4. Upload three object with three versions each (Total of 9 versions) // //***********************************************************************// Console.Write(string.Format(" [*] Uploading 3 objects with 3 versions each to bucket '{0}'... ", bucketName)); for (int i = 0; i < 3; i++) { string objectKey = String.Format("object-{0}", i); for (int j = 0; j < 3; j++) { string objectContent = String.Format("This is object {0}, revision {1}", i, j); PutObjectRequest poRequest = new PutObjectRequest() { BucketName = bucketName, Key = objectKey, ContentBody = objectContent }; PutObjectResponse poResponse = s3.PutObject(poRequest); if (poResponse.HttpStatusCode != System.Net.HttpStatusCode.OK) { Console.WriteLine("fail"); Console.ReadLine(); System.Environment.Exit(1); } Console.Write("."); } } Console.WriteLine("done"); //*******************************************// // 5. List the object versions in the bucket // //*******************************************// Console.WriteLine(" [*] Listing object versions..."); ListVersionsRequest request = new ListVersionsRequest() { BucketName = bucketName, // You can optionally specify key name prefix in the request // if you want list of object versions of a specific object. // For this example we limit response to return list of 2 versions. MaxKeys = 2 }; bool moreRecords = true; while (moreRecords) { ListVersionsResponse response = s3.ListVersions(request); foreach (S3ObjectVersion version in response.Versions) { Console.WriteLine(string.Format(" [x] -> Object key: {0}", version.Key)); Console.WriteLine(string.Format(" [x] VersionId: {0}", version.VersionId)); Console.WriteLine(string.Format(" [x] IsDeleteMarker: {0}", version.IsDeleteMarker)); Console.WriteLine(string.Format(" [x] LastModified: {0}", version.LastModified)); } // If response is truncated, set the marker to get the next // set of keys. if (response.IsTruncated) { request.KeyMarker = response.NextKeyMarker; request.VersionIdMarker = response.NextVersionIdMarker; } else { moreRecords = false; } Console.WriteLine(string.Format(" [x] More records? {0}", moreRecords)); } //*******************************************// // 6. Permanently delete the object versions // //*******************************************// Console.Write(" [*] Permanently deleting all object versions... "); ListVersionsResponse lv2Response = s3.ListVersions(bucketName); if (lv2Response.HttpStatusCode != System.Net.HttpStatusCode.OK) { Console.WriteLine("fail"); Console.ReadLine(); System.Environment.Exit(1); } foreach (S3ObjectVersion version in lv2Response.Versions) { DeleteObjectRequest do2Request = new DeleteObjectRequest() { BucketName = bucketName, Key = version.Key, VersionId = version.VersionId }; DeleteObjectResponse do2Response = s3.DeleteObject(do2Request); if (do2Response.HttpStatusCode != System.Net.HttpStatusCode.NoContent) { Console.WriteLine("fail"); Console.ReadLine(); System.Environment.Exit(1); } } Console.WriteLine("done"); //***********************// // 7. Delete the bucket // //***********************// Console.Write(String.Format(" [*] Deleting bucket '{0}' (sleeping 5 seconds)... ", bucketName)); System.Threading.Thread.Sleep(5000); DeleteBucketResponse dbRes = s3.DeleteBucket(bucketName); if (dbRes.HttpStatusCode != System.Net.HttpStatusCode.NoContent) { Console.WriteLine("fail"); Console.ReadLine(); System.Environment.Exit(1); } Console.WriteLine("done"); Console.WriteLine(" [*] Example is completed. Press any key to exit..."); Console.ReadLine(); }
public void GetBucketVersioning(GetBucketVersioningRequest request, Callback.OnSuccessCallback <CosResult> successCallback, Callback.OnFailedCallback failCallback) { Schedue(request, new GetBucketVersioningResult(), successCallback, failCallback); }
public GetBucketVersioningResult GetBucketVersioning(GetBucketVersioningRequest request) { return((Model.Bucket.GetBucketVersioningResult)Excute(request, new Model.Bucket.GetBucketVersioningResult())); }
public Task <GetBucketVersioningResponse> GetBucketVersioningAsync(GetBucketVersioningRequest request, CancellationToken cancellationToken = default) { throw new NotImplementedException(); }
/// <summary> /// 获取桶的多版本配置。 /// </summary> /// <param name="request">获取桶多版本配置的请求参数。</param> /// <returns>获取桶多版本配置的响应结果。</returns> public GetBucketVersioningResponse GetBucketVersioning(GetBucketVersioningRequest request) { return(this.DoRequest <GetBucketVersioningRequest, GetBucketVersioningResponse>(request)); }
public GetBucketVersioningResponse GetBucketVersioning(GetBucketVersioningRequest request) { throw new NotImplementedException(); }
public Task <GetBucketVersioningResponse> GetBucketVersioningAsync(GetBucketVersioningRequest request, CancellationToken token = default) { return(_requestHandler.SendRequestAsync <GetBucketVersioningRequest, GetBucketVersioningResponse>(request, token)); }
/// <summary> /// Start the asynchronous request for obtaining the bucket versioning configuration. /// </summary> /// <param name="request">Parameters in a request for obtaining bucket versioning configuration</param> /// <param name="callback">Asynchronous request callback function</param> /// <param name="state">Asynchronous request status object</param> /// <returns>Response to the asynchronous request</returns> public IAsyncResult BeginGetBucketVersioning(GetBucketVersioningRequest request, AsyncCallback callback, object state) { return(this.BeginDoRequest <GetBucketVersioningRequest>(request, callback, state)); }
public void GetBucketVersioningAsync(GetBucketVersioningRequest request, AmazonServiceCallback <GetBucketVersioningRequest, GetBucketVersioningResponse> callback, AsyncOptions options = null) { throw new System.NotImplementedException(); }