public static async Task <string> GetBucketRegionAsync(IAmazonS3 s3Client, string bucket) { try { var request = new GetBucketLocationRequest { BucketName = bucket }; var response = await s3Client.GetBucketLocationAsync(request); // Handle the legacy naming conventions if (response.Location == S3Region.US) { return("us-east-1"); } if (response.Location == S3Region.EU) { return("eu-west-1"); } return(response.Location.Value); } catch (Exception e) { throw new LambdaToolsException($"Error determining region for bucket {bucket}: {e.Message}", LambdaToolsException.ErrorCode.S3GetBucketLocation, e); } }
public static void AsynGetBuckeLocation(COSXML.CosXml cosXml, string bucket) { GetBucketLocationRequest request = new GetBucketLocationRequest(bucket); //设置签名有效时长 request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); ///执行请求 cosXml.GetBucketLocation(request, delegate(CosResult cosResult) { GetBucketLocationResult result = cosResult as GetBucketLocationResult; 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> /// Determines whether the specified path is a directory. /// </summary> /// <param name="path">The path.</param> /// <returns></returns> public bool IsDirectory(string path) { var client = InitialiseClient(); var request = new GetBucketLocationRequest { BucketName = ExtractBucketNameFromPath(path) }; try { // If the bucket location can be retrieved it's a valid bucket var response = client.GetBucketLocation(request); return(response.HttpStatusCode == HttpStatusCode.OK); } catch (AmazonS3Exception ex) { if (ex.Message.Contains("does not exist")) { return(false); } throw ex; } }
private async Task <string> FindBucketLocationAsync(string repositoryName, string branchName) { var request = new GetBucketLocationRequest() { BucketName = GetBucketName(repositoryName, branchName) }; GetBucketLocationResponse response = await s3Client.GetBucketLocationAsync(request); return(response.Location.ToString()); }
static string FindBucketLocation(IAmazonS3 client) { GetBucketLocationRequest request = new GetBucketLocationRequest() { BucketName = bucketName }; GetBucketLocationResponse response = client.GetBucketLocation(request); var bucketLocation = response.Location.ToString(); return(bucketLocation); }
/// <summary> /// Get the S3 bucket's region. /// </summary> /// <param name="client"></param> /// <returns>The S3Region object representing the bucket region</returns> private async Task <S3Region> GetBucketLocationAsync(IAmazonS3 client) { GetBucketLocationRequest request = new GetBucketLocationRequest { BucketName = Environment.GetEnvironmentVariable("BUCKET_NAME") }; GetBucketLocationResponse response = await client.GetBucketLocationAsync(request); return(response.Location); }
private static async Task <string> FindBucketLocationAsync(IAmazonS3 client, string bucketName) { var request = new GetBucketLocationRequest() { BucketName = bucketName }; GetBucketLocationResponse response = await client.GetBucketLocationAsync(request); var bucketLocation = response.Location.ToString(); return(bucketLocation); }
private static async Task <string> FindBucketLocationAsync() { var request = new GetBucketLocationRequest() { BucketName = BUCKET_NAME }; GetBucketLocationResponse response = await _s3Client.GetBucketLocationAsync(request); string bucketLocation = response.Location.ToString(); return(bucketLocation); }
static async Task <string> FindBucketLocation(IAmazonS3 client) { string bucketLocation; GetBucketLocationRequest request = new GetBucketLocationRequest() { BucketName = bucket }; GetBucketLocationResponse response = await client.GetBucketLocationAsync(request); bucketLocation = response.Location.ToString(); return(bucketLocation); }
public static RegionEndpoint GetBucketLocation(IAmazonS3 s3Client, string bucketName) { GetBucketLocationRequest getBucketLocationRequest = new GetBucketLocationRequest() { BucketName = bucketName }; GetBucketLocationResponse getBucketLocationResponse = s3Client.GetBucketLocation(getBucketLocationRequest); S3Region s3Region = getBucketLocationResponse.Location; return(toRegionEndpoint(s3Region)); }
public async Task <string> FindBucketLocationAsync(string bucketName) { string bucketLocation; var request = new GetBucketLocationRequest() { BucketName = bucketName }; GetBucketLocationResponse response = await s3Client.GetBucketLocationAsync(request); bucketLocation = response.Location.ToString(); return(bucketLocation); }
private static async Task <string> GetBucketRegionAsync(IAmazonS3 s3Client, string bucket) { var request = new GetBucketLocationRequest { BucketName = bucket }; var response = await s3Client.GetBucketLocationAsync(request); // Handle the legacy naming conventions if (response.Location == S3Region.US) { return("us-east-1"); } if (response.Location == S3Region.EU) { return("eu-west-1"); } return(response.Location.Value); }
static void GetBucketLocation() { try { GetBucketLocationRequest request = new GetBucketLocationRequest() { BucketName = bucketName }; GetBucketLocationResponse response = client.GetBucketLocation(request); Console.WriteLine("Get bucket location response: {0}", response.StatusCode); Console.WriteLine("Bucket Location: {0}", response.Location); } catch (ObsException ex) { Console.WriteLine("Exception errorcode: {0}, when get bucket location.", ex.ErrorCode); Console.WriteLine("Exception errormessage: {0}", ex.ErrorMessage); } }
private void GetBucketLocationButton_Click(object sender, RoutedEventArgs e) { try { S3Common.client.OnS3Response += GetBucketLocationWebResponse; GetBucketLocationRequest request = new GetBucketLocationRequest(); request.BucketName = SelectedBucketName; S3Common.client.GetBucketLocation(request); } catch (Exception ex) { S3Common.client.OnS3Response -= GetBucketLocationWebResponse; this.Dispatcher.BeginInvoke(() => { MessageBox.Show(ex.Message); }); } }
private static void CreateBucket() { var configuration = Construction.GetConfiguration(); var bucketName = configuration["S3BucketName"]; using (var s3Client = Construction.GetAmazonS3Client()) { // Create bucket. try { var putBucketRequest = new PutBucketRequest { BucketName = bucketName, UseClientRegion = true, }; var putBucketResponse = s3Client.PutBucketAsync(putBucketRequest).Result; Construction.DisplayPutBucketResponse(putBucketResponse); } catch (AmazonS3Exception ex) { Console.WriteLine($"{nameof(AmazonS3Exception)}:\n{ex.Message}"); } catch (Exception ex) { Console.WriteLine($"{nameof(Exception)}:\n{ex.Message}"); } // Get bucket location. var getBucketLocationRequest = new GetBucketLocationRequest { BucketName = bucketName, }; var getBucketLocationResponse = s3Client.GetBucketLocationAsync(getBucketLocationRequest).Result; Construction.DisplayGetBucketLocationResponse(getBucketLocationResponse); } }
// Return a list of folders (buckets) // Returns collection of CloudFolder objects, or null on error. public override List <CloudFolder> ListFolders() { try { this.Exception = null; List <CloudFolder> results = new List <CloudFolder>(); Task <ListBucketsResponse> task = StorageClient.ListBucketsAsync(); task.Wait(); ListBucketsResponse response = task.Result; if (response != null && response.Buckets != null) { foreach (S3Bucket bucket in response.Buckets) { GetBucketLocationRequest GBLrequest = new GetBucketLocationRequest() { BucketName = bucket.BucketName }; Task <GetBucketLocationResponse> task2 = StorageClient.GetBucketLocationAsync(GBLrequest); task2.Wait(); GetBucketLocationResponse GBLresponse = task2.Result; if (GBLresponse.Location == this.Region) { results.Add(new CloudFolder(bucket.BucketName, this.Account, bucket)); } } } return(results); } catch (Exception ex) { this.Exception = ex; if (!this.HandleErrors) { throw ex; } return(null); } }
public static void GetBuckeLocation(COSXML.CosXml cosXml, string bucket) { try { GetBucketLocationRequest request = new GetBucketLocationRequest(bucket); //设置签名有效时长 request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); //执行请求 GetBucketLocationResult result = cosXml.GetBucketLocation(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 GetBucketLocationResult GetBucketLocation(GetBucketLocationRequest request) { return((Model.Bucket.GetBucketLocationResult)excute(request, new Model.Bucket.GetBucketLocationResult())); }
public Task <GetBucketLocationResponse> GetBucketLocationAsync(GetBucketLocationRequest request, CancellationToken cancellationToken = default) { throw new NotImplementedException(); }
public static GetBucketLocationResponse GetBucketLocation(this IAmazonS3 client, GetBucketLocationRequest request) { return(client.GetBucketLocationAsync(request).GetResult()); }
/// <summary> /// Start the asynchronous request for obtaining the bucket location. /// </summary> /// <param name="request">Parameters in a request for obtaining the bucket location</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 BeginGetBucketLocation(GetBucketLocationRequest request, AsyncCallback callback, object state) { return(BeginDoRequest <GetBucketLocationRequest>(request, callback, state)); }
/// <summary> /// 获取桶的区域位置。 /// </summary> /// <param name="request">获取桶区域位置的请求参数。</param> /// <returns>获取桶区域位置的响应结果。</returns> public GetBucketLocationResponse GetBucketLocation(GetBucketLocationRequest request) { return(DoRequest <GetBucketLocationRequest, GetBucketLocationResponse>(request)); }
public void BucketSamples() { { #region ListBuckets Sample // Create a client AmazonS3Client client = new AmazonS3Client(); // Issue call ListBucketsResponse response = client.ListBuckets(); // View response data Console.WriteLine("Buckets owner - {0}", response.Owner.DisplayName); foreach (S3Bucket bucket in response.Buckets) { Console.WriteLine("Bucket {0}, Created on {1}", bucket.BucketName, bucket.CreationDate); } #endregion } { #region BucketPolicy Sample // Create a client AmazonS3Client client = new AmazonS3Client(); // Put sample bucket policy (overwrite an existing policy) string newPolicy = @"{ ""Statement"":[{ ""Sid"":""BasicPerms"", ""Effect"":""Allow"", ""Principal"": ""*"", ""Action"":[""s3:PutObject"",""s3:GetObject""], ""Resource"":[""arn:aws:s3:::samplebucketname/*""] }]}"; PutBucketPolicyRequest putRequest = new PutBucketPolicyRequest { BucketName = "SampleBucket", Policy = newPolicy }; client.PutBucketPolicy(putRequest); // Retrieve current policy GetBucketPolicyRequest getRequest = new GetBucketPolicyRequest { BucketName = "SampleBucket" }; string policy = client.GetBucketPolicy(getRequest).Policy; Console.WriteLine(policy); Debug.Assert(policy.Contains("BasicPerms")); // Delete current policy DeleteBucketPolicyRequest deleteRequest = new DeleteBucketPolicyRequest { BucketName = "SampleBucket" }; client.DeleteBucketPolicy(deleteRequest); // Retrieve current policy and verify that it is null policy = client.GetBucketPolicy(getRequest).Policy; Debug.Assert(policy == null); #endregion } { #region GetBucketLocation Sample // Create a client AmazonS3Client client = new AmazonS3Client(); // Construct request GetBucketLocationRequest request = new GetBucketLocationRequest { BucketName = "SampleBucket" }; // Issue call GetBucketLocationResponse response = client.GetBucketLocation(request); // View response data Console.WriteLine("Bucket location - {0}", response.Location); #endregion } { #region PutBucket Sample // Create a client AmazonS3Client client = new AmazonS3Client(); // Construct request PutBucketRequest request = new PutBucketRequest { BucketName = "SampleBucket", BucketRegion = S3Region.EU, // set region to EU CannedACL = S3CannedACL.PublicRead // make bucket publicly readable }; // Issue call PutBucketResponse response = client.PutBucket(request); #endregion } { #region DeleteBucket Sample 1 // Create a client AmazonS3Client client = new AmazonS3Client(); // Construct request DeleteBucketRequest request = new DeleteBucketRequest { BucketName = "SampleBucket" }; // Issue call DeleteBucketResponse response = client.DeleteBucket(request); #endregion } { #region DeleteBucket Sample 2 // Create a client AmazonS3Client client = new AmazonS3Client(); // List and delete all objects ListObjectsRequest listRequest = new ListObjectsRequest { BucketName = "SampleBucket" }; ListObjectsResponse listResponse; do { // Get a list of objects listResponse = client.ListObjects(listRequest); foreach (S3Object obj in listResponse.S3Objects) { // Delete each object client.DeleteObject(new DeleteObjectRequest { BucketName = "SampleBucket", Key = obj.Key }); } // Set the marker property listRequest.Marker = listResponse.NextMarker; } while (listResponse.IsTruncated); // Construct DeleteBucket request DeleteBucketRequest request = new DeleteBucketRequest { BucketName = "SampleBucket" }; // Issue call DeleteBucketResponse response = client.DeleteBucket(request); #endregion } { #region LifecycleConfiguration Sample // Create a client AmazonS3Client client = new AmazonS3Client(); // Put sample lifecycle configuration (overwrite an existing configuration) LifecycleConfiguration newConfiguration = new LifecycleConfiguration { Rules = new List <LifecycleRule> { // Rule to delete keys with prefix "Test-" after 5 days new LifecycleRule { Prefix = "Test-", Expiration = new LifecycleRuleExpiration { Days = 5 } }, // Rule to delete keys in subdirectory "Logs" after 2 days new LifecycleRule { Prefix = "Logs/", Expiration = new LifecycleRuleExpiration { Days = 2 }, Id = "log-file-removal" } } }; PutLifecycleConfigurationRequest putRequest = new PutLifecycleConfigurationRequest { BucketName = "SampleBucket", Configuration = newConfiguration }; client.PutLifecycleConfiguration(putRequest); // Retrieve current configuration GetLifecycleConfigurationRequest getRequest = new GetLifecycleConfigurationRequest { BucketName = "SampleBucket" }; LifecycleConfiguration configuration = client.GetLifecycleConfiguration(getRequest).Configuration; Console.WriteLine("Configuration contains {0} rules", configuration.Rules.Count); foreach (LifecycleRule rule in configuration.Rules) { Console.WriteLine("Rule"); Console.WriteLine(" Prefix = " + rule.Prefix); Console.WriteLine(" Expiration (days) = " + rule.Expiration.Days); Console.WriteLine(" Id = " + rule.Id); Console.WriteLine(" Status = " + rule.Status); } // Put a new configuration and overwrite the existing configuration configuration.Rules.RemoveAt(0); // remove first rule client.PutLifecycleConfiguration(putRequest); // Delete current configuration DeleteLifecycleConfigurationRequest deleteRequest = new DeleteLifecycleConfigurationRequest { BucketName = "SampleBucket" }; client.DeleteLifecycleConfiguration(deleteRequest); // Retrieve current configuration and verify that it is null configuration = client.GetLifecycleConfiguration(getRequest).Configuration; Debug.Assert(configuration == null); #endregion } }
/// <summary> /// Queries S3 to determine whether the given bucket resides in the Europe location. /// </summary> public bool IsBucketInEurope(string bucketName) { var request = new GetBucketLocationRequest(this, bucketName); using (GetBucketLocationResponse response = request.GetResponse()) return response.IsEurope; }
internal bool ExistsWithBucketCheck(out bool bucketExists) { bucketExists = true; try { if (String.IsNullOrEmpty(bucket)) { return(true); } else if (String.IsNullOrEmpty(key)) { var request = new GetBucketLocationRequest() { BucketName = bucket }; ((Amazon.Runtime.Internal.IAmazonWebServiceRequest)request).AddBeforeRequestHandler(S3Helper.FileIORequestEventHandler); try { s3Client.GetBucketLocationAsync(request).Wait(); return(true); } catch (AmazonS3Exception e) { if (string.Equals(e.ErrorCode, "NoSuchBucket")) { return(false); } throw; } } else { var request = new ListObjectsRequest() { BucketName = this.bucket, Prefix = S3Helper.EncodeKey(key), MaxKeys = 1 }; ((Amazon.Runtime.Internal.IAmazonWebServiceRequest)request).AddBeforeRequestHandler(S3Helper.FileIORequestEventHandler); Task <ListObjectsResponse> t = s3Client.ListObjectsAsync(request); t.Wait(); var response = t.Result; return(response.S3Objects.Count > 0); } } catch (AmazonS3Exception e) { if (string.Equals(e.ErrorCode, "NoSuchBucket")) { bucketExists = false; return(false); } else if (string.Equals(e.ErrorCode, "NotFound")) { return(false); } throw; } }
public GetBucketLocationResponse GetBucketLocation(GetBucketLocationRequest request) { throw new NotImplementedException(); }
public void GetBucketLocation(GetBucketLocationRequest request, Callback.OnSuccessCallback <CosResult> successCallback, Callback.OnFailedCallback failCallback) { schedue(request, new GetBucketLocationResult(), successCallback, failCallback); }
public void GetBucketLocationAsync(GetBucketLocationRequest request, AmazonServiceCallback <GetBucketLocationRequest, GetBucketLocationResponse> callback, AsyncOptions options = null) { throw new System.NotImplementedException(); }