static void Main(string[] args) { Console.WriteLine("Hello World!"); const string bucketname = "test-bucket"; List <FileS3> Files = new List <FileS3>() { new FileS3("fileNameTest.txt", "sample file content 1"), new FileS3("fileNameTest1.txt", "sample file content 2"), new FileS3("fileNameTest2.txt", "sample file content 3"), new FileS3("fileNameTest3.txt", "sample file content 4"), new FileS3("fileNameTest4.txt", "sample file content 5") }; S3wapper wapper = new S3wapper(AwsLocalBuilder.LocalS3Credentials()); var createResult = wapper.PutBucketAsync(bucketname).Result; Console.WriteLine($"create bucket {bucketname} {createResult}"); var listbuckets = wapper.ListBucketsAsync().Result.ToList(); listbuckets .ForEach(async b => { Console.WriteLine(b); Files.ForEach(async f => { await wapper.PutObjectAsync(b, f.Name, f.Body); Console.WriteLine($"upload file {b} {f.Name}"); } ); var listobjects = wapper.ListObjectsAsync(b).Result.ToList(); if (listobjects.Any()) { Console.WriteLine(JsonConvert.SerializeObject(listobjects)); var result = await wapper.DeleteObjectsAsync(b, listobjects); Console.WriteLine($"all file deleted {result}"); } }); Console.ReadKey(); }
static void Main(string[] args) { ConfigurationManager configManager = new ConfigurationManager(); IConfiguration config = configManager.BuildConfig(); var listobjects = config.GetSection("filesToDelete").Get <string[]>(); Console.WriteLine("Hello World!"); string bucketname = config.GetSection("bucketname").Get <string>(); var filenames = JsonConvert.SerializeObject(listobjects); S3wapper wapper = new S3wapper(AwsLocalBuilder.LocalS3Credentials()); if (listobjects.Any()) { Console.WriteLine(JsonConvert.SerializeObject(listobjects)); var result = wapper.DeleteObjectsAsync(bucketname, listobjects).Result; Console.WriteLine($"all file deleted {result}"); } Console.ReadKey(); }