private static void Main(string[] args) { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; /// Note: s3 AccessKey and SecretKey needs to be added in App.config file /// See instructions in README.md on running examples for more information. var minio = new MinioClient() .WithEndpoint("play.min.io") .WithCredentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG") .WithSSL() .Build(); var getListBucketsTask = minio.ListBucketsAsync(); try { Task.WaitAll(getListBucketsTask); // block while the task completes } catch (AggregateException aggEx) { aggEx.Handle(HandleBatchExceptions); } var list = getListBucketsTask.Result; foreach (var bucket in list.Buckets) { Console.WriteLine(bucket.Name + " " + bucket.CreationDateDateTime); } //Supply a new bucket name var bucketName = "mynewbucket"; if (isBucketExists(minio, bucketName)) { var remBuckArgs = new RemoveBucketArgs() .WithBucket(bucketName); var removeBucketTask = minio.RemoveBucketAsync(remBuckArgs); Task.WaitAll(removeBucketTask); } var mkBktArgs = new MakeBucketArgs() .WithBucket(bucketName); Task.WaitAll(minio.MakeBucketAsync(mkBktArgs)); var found = isBucketExists(minio, bucketName); Console.WriteLine("Bucket exists? = " + found); Console.ReadLine(); }
public async Task TestInvalidObjectNameError() { var badName = new string('A', 260); var bucketName = Guid.NewGuid().ToString("N"); var minio = new MinioClient() .WithEndpoint("play.min.io") .WithCredentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG") .Build(); try { const int tryCount = 5; var mkBktArgs = new MakeBucketArgs() .WithBucket(bucketName); await minio.MakeBucketAsync(mkBktArgs); var statObjArgs = new StatObjectArgs() .WithBucket(bucketName) .WithObject(badName); var ex = await Assert.ThrowsExceptionAsync <InvalidObjectNameException>( () => minio.StatObjectAsync(statObjArgs)); for (int i = 0; i < tryCount && (ex.ServerResponse != null && ex.ServerResponse.StatusCode.Equals(HttpStatusCode.ServiceUnavailable)); ++i) { ex = await Assert.ThrowsExceptionAsync <InvalidObjectNameException>( () => minio.StatObjectAsync(statObjArgs)); } Assert.AreEqual(ex.Response.Code, "InvalidObjectName"); GetObjectArgs getObjectArgs = new GetObjectArgs() .WithBucket(bucketName) .WithObject(badName) .WithCallbackStream(s => {}); ex = await Assert.ThrowsExceptionAsync <InvalidObjectNameException>( () => minio.GetObjectAsync(getObjectArgs)); Assert.AreEqual(ex.Response.Code, "InvalidObjectName"); } finally { var args = new RemoveBucketArgs() .WithBucket(bucketName); await minio.RemoveBucketAsync(args); } }