public static void WaitForBucket(IAmazonS3 client, string bucketName, int maxSeconds) { var sleeper = UtilityMethods.ListSleeper.Create(); UtilityMethods.WaitUntilSuccess(() => { //Check if a bucket exists by trying to put an object in it var key = Guid.NewGuid().ToString() + "_existskey"; var res = client.PutObject(new PutObjectRequest { BucketName = bucketName, Key = key, ContentBody = "exists..." }); try { client.Delete(bucketName, key, null); } catch { Console.WriteLine($"Eventual consistency error: failed to delete key {key} from bucket {bucketName}"); } return(true); }); //Double check the bucket still exists using the DoesBucketExistV2 method var exists = S3TestUtils.WaitForConsistency(() => { return(AmazonS3Util.DoesS3BucketExistV2(client, bucketName) ? (bool?)true : null); }); }
internal void RenameObject(String sourceKey, String destKey) { CopyObjectRequest request = new CopyObjectRequest() { CannedACL = S3CannedACL.PublicRead, DestinationBucket = _bucketName, DestinationKey = GetFullPrefix(destKey), MetadataDirective = S3MetadataDirective.COPY, SourceBucket = _bucketName, SourceKey = GetFullPrefix(sourceKey) }; S3ItemData destination = GetObject(destKey); if (destination != null) { throw new Exception(String.Format("Destination object with key {0} already exists.", request.DestinationKey)); } CopyObjectResponse response = _S3Client.CopyObject(request); if (response.HttpStatusCode != System.Net.HttpStatusCode.OK) { throw new Exception(String.Format("Failed to copy {0} to {1}", request.SourceKey, request.DestinationKey)); } _S3Client.Delete(_bucketName, request.SourceKey, null); }
public override void Delete(string path) { _s3Client.Delete(_bucketName, path, new Dictionary <string, object>()); }