using Minio; using Minio.Exceptions; using Minio.DataModel; publicstaticvoidUploadFile() { var endpoint = "127.0.0.1:9000"; var accessKey = "minioadmin"; var secretKey = "minioadmin";
var minio = new MinioClient() .WithEndpoint(endpoint) .WithCredentials(accessKey, secretKey) .Build(); Run(minio).Wait(); } privateasyncstatic Task Run(MinioClient minio) { var bucketName = "firstbucket"; var location = "us-east-1"; var objectName = "1.bmp"; var filePath = "D:\\BBK\\1.bmp"; var contentType = "application/bmp";
try { // Make a bucket on the server, if not already present. var beArgs = new BucketExistsArgs() .WithBucket(bucketName); bool found = await minio.BucketExistsAsync(beArgs).ConfigureAwait(false); if (!found) { var mbArgs = new MakeBucketArgs() .WithBucket(bucketName); await minio.MakeBucketAsync(mbArgs).ConfigureAwait(false); } // Upload a file to bucket. var putObjectArgs = new PutObjectArgs() .WithBucket(bucketName) .WithObject(objectName) .WithFileName(filePath) .WithContentType(contentType); await minio.PutObjectAsync(putObjectArgs).ConfigureAwait(false); Console.WriteLine("Successfully uploaded " + objectName); } catch (MinioException e) { Console.WriteLine("File Upload Error: {0}", e.Message); } }