0

I have created a folder on Amazon S3 bucket named as 'test' using following code

            var bucketName = ConfigurationManager.AppSettings["bucketName"].ToString();
            var AccessKey = ConfigurationManager.AppSettings["AccessKey"].ToString();
            var SecretAccessKey = ConfigurationManager.AppSettings["SecretAccessKey"].ToString();
            IAmazonS3 client = new AmazonS3Client(AccessKey, SecretAccessKey, RegionEndpoint.USWest2);


            //Create folder with company name

            var folderKey = "test"+ "/"; 
            PutObjectRequest request = new PutObjectRequest();
            request.BucketName = bucketName;
            request.StorageClass = S3StorageClass.Standard;
            request.ServerSideEncryptionMethod = ServerSideEncryptionMethod.None;
            request.Key = folderKey;
            request.ContentBody = string.Empty;
            PutObjectResponse response = client.PutObject(request);       

Now I want to check whether it is exist there or not..

Found some solution here on link which is in ruby, but i need solution in C#

devSS
  • 39
  • 2
  • 7

1 Answers1

0

I would suggest to use AWSSDK.S3 NuGet package. This way you can create a AmazonS3Client and Get a list of buckets by calling var bucketsResponse = await client.ListBucketsAsync() then you can do if (bucketsResponse.Buckets.Any(x => x.BucketName == "test")) to check if your 'test' bucket exists.

Fabian Claasen
  • 254
  • 2
  • 14