### Run Example Projects Source: https://github.com/minio/minio-dotnet/blob/master/DEVELOPMENT.md Commands to execute the provided example projects using the .NET CLI. ```bash dotnet run --project Minio.Examples.Simple ``` ```bash dotnet run --project Minio.Examples.Host ``` ```bash dotnet run --project Minio.Examples.Host --framework net8.0 ``` -------------------------------- ### Execute MinIO Example Projects Source: https://github.com/minio/minio-dotnet/blob/master/README.md Run the provided example projects using the .NET CLI. ```bash dotnet run --project Minio.Examples.Simple # or dotnet run --project Minio.Examples.Host ``` -------------------------------- ### Verify .NET Installation Source: https://github.com/minio/minio-dotnet/blob/master/DEVELOPMENT.md Check the currently installed version of the .NET SDK. ```bash dotnet --version ``` -------------------------------- ### Install .NET SDK on Windows Source: https://github.com/minio/minio-dotnet/blob/master/DEVELOPMENT.md Use the Windows Package Manager to install the .NET 10 SDK. ```bash winget install Microsoft.DotNet.SDK.10 ``` -------------------------------- ### Install .NET SDK on macOS Source: https://github.com/minio/minio-dotnet/blob/master/DEVELOPMENT.md Use Homebrew to install the .NET SDK on macOS. ```bash brew install dotnet ``` -------------------------------- ### Install .NET SDK on Linux Source: https://github.com/minio/minio-dotnet/blob/master/DEVELOPMENT.md Use apt-get to install the .NET 10 SDK on Debian or Ubuntu distributions. ```bash sudo apt-get update && sudo apt-get install -y dotnet-sdk-10.0 ``` -------------------------------- ### MinIO Client Creation Source: https://context7.com/minio/minio-dotnet/llms.txt Examples of how to create an IMinioClient instance using MinioClientBuilder or dependency injection. ```APIDOC ## MinIO Client Creation ### Description Examples of how to create an `IMinioClient` instance using `MinioClientBuilder` for direct instantiation or via dependency injection for ASP.NET Core applications. ### MinioClientBuilder #### Create client with static credentials ```csharp using Minio; using Minio.Model; var client = new MinioClientBuilder("http://localhost:9000") .WithStaticCredentials("minioadmin", "minioadmin") .Build(); ``` #### Create client with custom region ```csharp using Minio; using Minio.Model; var clientWithRegion = new MinioClientBuilder("https://s3.eu-west-1.amazonaws.com") .WithRegion("eu-west-1") .WithStaticCredentials("accessKey", "secretKey", sessionToken: null) .Build(); ``` #### Create client using environment credentials (MINIO_ROOT_USER, MINIO_ROOT_PASSWORD) ```csharp using Minio; using Minio.Model; var envClient = new MinioClientBuilder("http://localhost:9000") .WithEnvironmentCredentials() .Build(); ``` ### Dependency Injection #### Register MinIO with static credentials ```csharp using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Minio; var builder = Host.CreateApplicationBuilder(args); builder.Services .AddMinio("http://localhost:9000") .WithStaticCredentials("minioadmin", "minioadmin"); using var host = builder.Build(); var minioClient = host.Services.GetRequiredService(); ``` #### Register MinIO using environment credentials ```csharp using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Minio; var builder = Host.CreateApplicationBuilder(args); builder.Services .AddMinio("http://localhost:9000") .WithEnvironmentCredentials(); using var host = builder.Build(); var minioClient = host.Services.GetRequiredService(); ``` #### Configure MinIO via options delegate ```csharp using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Minio; var builder = Host.CreateApplicationBuilder(args); builder.Services .AddMinio(opts => { opts.EndPoint = new Uri("https://minio.example.com"); opts.Region = "us-east-1"; }) .WithStaticCredentials(opts => { opts.AccessKey = "accessKey"; opts.SecretKey = "secretKey"; }); using var host = builder.Build(); var minioClient = host.Services.GetRequiredService(); ``` ``` -------------------------------- ### Run MinIO Server via Docker Source: https://github.com/minio/minio-dotnet/blob/master/README.md Start a local MinIO instance using Docker for development and testing purposes. ```bash docker run --rm -p 9000:9000 quay.io/minio/minio:latest server /data ``` -------------------------------- ### Manage Bucket Policies with MinIO .NET SDK Source: https://context7.com/minio/minio-dotnet/llms.txt Illustrates setting, retrieving, and removing bucket policies for fine-grained access control. Example shows setting public read access. ```csharp using Minio; var client = new MinioClientBuilder("http://localhost:9000") .WithStaticCredentials("minioadmin", "minioadmin") .Build(); // Set bucket policy (public read access) var publicReadPolicy = """ { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": {"AWS": ["*"]}, "Action": ["s3:GetObject"], "Resource": ["arn:aws:s3:::my-bucket/public/*"] } ] } """; await client.SetPolicyAsync("my-bucket", publicReadPolicy); Console.WriteLine("Policy set"); // Get current policy var policy = await client.GetPolicyAsync("my-bucket"); if (policy != null) { Console.WriteLine($"Current policy:\n{policy}"); } else { Console.WriteLine("No policy set"); } // Remove bucket policy await client.RemovePolicyAsync("my-bucket"); Console.WriteLine("Policy removed"); ``` -------------------------------- ### Configure Bucket Encryption with MinIO .NET SDK Source: https://context7.com/minio/minio-dotnet/llms.txt Shows how to set, get, and remove server-side encryption configurations for a bucket. Supports SSE-S3 and SSE-KMS algorithms. ```csharp using Minio; using Minio.Model; var client = new MinioClientBuilder("http://localhost:9000") .WithStaticCredentials("minioadmin", "minioadmin") .Build(); // Set default encryption (SSE-S3) var encryptionConfig = new BucketEncryptionConfiguration { Rules = { new ServerSideEncryptionRule { ApplyServerSideEncryptionByDefault = new ApplyServerSideEncryptionByDefault { SSEAlgorithm = "AES256" } } } }; await client.SetBucketEncryptionAsync("my-bucket", encryptionConfig); // Get current encryption configuration var config = await client.GetBucketEncryptionAsync("my-bucket"); Console.WriteLine($"Encryption rules: {config.Rules.Count}"); // Remove encryption configuration await client.RemoveBucketEncryptionAsync("my-bucket"); ``` -------------------------------- ### GET /bucket Source: https://context7.com/minio/minio-dotnet/llms.txt Lists objects in a bucket with support for filtering, pagination, and metadata inclusion. ```APIDOC ## GET /bucket ### Description Lists objects in a bucket with optional filtering by prefix and delimiter. Returns an IAsyncEnumerable for efficient streaming. ### Method GET ### Endpoint /{bucket} ### Parameters #### Path Parameters - **bucket** (string) - Required - The name of the bucket. #### Query Parameters - **prefix** (string) - Optional - Filter results by prefix. - **delimiter** (string) - Optional - Character used for grouping keys. - **pageSize** (int) - Optional - Number of items per page. - **includeMetadata** (bool) - Optional - Whether to include user metadata in the response. ``` -------------------------------- ### Generate Presigned GET URL Source: https://context7.com/minio/minio-dotnet/llms.txt Generates a presigned URL for temporary GET access to an object. This allows users to download objects without needing Minio credentials for a specified duration. Supports custom response headers and specific object versions. ```csharp using Minio; var client = new MinioClientBuilder("http://localhost:9000") .WithStaticCredentials("minioadmin", "minioadmin") .Build(); // Generate URL valid for 1 hour Uri downloadUrl = await client.PresignedGetObjectAsync( "my-bucket", "documents/report.pdf", TimeSpan.FromHours(1) ); Console.WriteLine($"Download URL: {downloadUrl}"); // Share this URL - anyone can download without credentials until expiry // Generate URL with custom response headers Uri customUrl = await client.PresignedGetObjectAsync( "my-bucket", "image.png", TimeSpan.FromMinutes(30), responseHeaders: new Dictionary { ["response-content-disposition"] = "attachment; filename=\"download.png\"", ["response-content-type"] = "application/octet-stream" } ); // Generate URL for specific version Uri versionedUrl = await client.PresignedGetObjectAsync( "my-bucket", "file.txt", TimeSpan.FromHours(2), versionId: "version-abc123" ); ``` -------------------------------- ### PresignedGetObjectAsync Source: https://context7.com/minio/minio-dotnet/llms.txt Generates a presigned URL for temporary GET access to an object. This allows users to download an object without needing Minio credentials for a specified duration. ```APIDOC ## PresignedGetObjectAsync Generates a presigned URL granting temporary GET access to an object without requiring credentials. ### Method GET ### Endpoint /api/v1/objects/presigned-get ### Parameters #### Path Parameters - **bucketName** (string) - Required - The name of the bucket. - **objectName** (string) - Required - The name of the object. #### Query Parameters - **expires** (TimeSpan) - Required - The duration for which the presigned URL will be valid. - **versionId** (string) - Optional - The version ID of the object to generate the URL for. - **responseHeaders** (Dictionary) - Optional - Custom response headers to be included in the presigned URL, such as `response-content-disposition` and `response-content-type`. ### Request Example (1 Hour Expiry) ```csharp Uri downloadUrl = await client.PresignedGetObjectAsync( "my-bucket", "documents/report.pdf", TimeSpan.FromHours(1) ); ``` ### Request Example (With Response Headers) ```csharp Uri customUrl = await client.PresignedGetObjectAsync( "my-bucket", "image.png", TimeSpan.FromMinutes(30), responseHeaders: new Dictionary { ["response-content-disposition"] = "attachment; filename=\"download.png\"", ["response-content-type"] = "application/octet-stream" } ); ``` ### Response #### Success Response (200) - **Uri** (Uri) - The generated presigned URL. #### Response Example ```json { "Uri": "http://localhost:9000/my-bucket/documents/report.pdf?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=..." } ``` ``` -------------------------------- ### Get Object Async Source: https://context7.com/minio/minio-dotnet/llms.txt Downloads an object from a bucket, returning an `ObjectInfoStream` that includes both the content stream and metadata. The caller is responsible for disposing of the returned stream. ```csharp using Minio; using Minio.Model; var client = new MinioClientBuilder("http://localhost:9000") .WithStaticCredentials("minioadmin", "minioadmin") .Build(); // Download object to file await using var result = await client.GetObjectAsync("my-bucket", "documents/report.pdf"); await using var fileStream = File.Create("downloaded-report.pdf"); await result.CopyToAsync(fileStream); Console.WriteLine($"Downloaded: {result.ObjectInfo.Key}"); Console.WriteLine($"Size: {result.ObjectInfo.ContentLength} bytes"); Console.WriteLine($"Content-Type: {result.ObjectInfo.ContentType}"); Console.WriteLine($"ETag: {result.ObjectInfo.Etag}"); ``` ```csharp using Minio; using Minio.Model; var client = new MinioClientBuilder("http://localhost:9000") .WithStaticCredentials("minioadmin", "minioadmin") .Build(); // Download with byte range (partial content) var rangeOptions = new GetObjectOptions { Range = new S3Range(0, 1023) // First 1KB only }; await using var partialResult = await client.GetObjectAsync("my-bucket", "large-file.bin", rangeOptions); ``` ```csharp using Minio; using Minio.Model; var client = new MinioClientBuilder("http://localhost:9000") .WithStaticCredentials("minioadmin", "minioadmin") .Build(); // Download specific version var versionOptions = new GetObjectOptions { VersionId = "abc123-version-id" }; await using var versionedResult = await client.GetObjectAsync("my-bucket", "file.txt", versionOptions); ``` -------------------------------- ### Generate Presigned POST Policy with C# Source: https://context7.com/minio/minio-dotnet/llms.txt Generates a presigned POST policy for browser-based multipart/form-data uploads. Supports defining conditions like content length and type. Includes an HTML form example. ```csharp using Minio; using Minio.Model; var client = new MinioClientBuilder("http://localhost:9000") .WithStaticCredentials("minioadmin", "minioadmin") .Build(); // Create POST policy with conditions var conditions = new List { PostPolicyCondition.ContentLengthRange(1, 10 * 1024 * 1024), // 1 byte to 10MB PostPolicyCondition.StartsWith("Content-Type", "image/") // Only images }; var result = await client.PresignedPostPolicyAsync( "my-bucket", "uploads/${filename}", TimeSpan.FromHours(1), conditions ); Console.WriteLine($"Upload URL: {result.Url}"); Console.WriteLine("Form fields:"); foreach (var (key, value) in result.FormData) { Console.WriteLine($" {key}: {value}"); } // Use in HTML form: //
// {foreach field in result.FormData: } // // //
``` -------------------------------- ### Generate Presigned PUT URL with C# Source: https://context7.com/minio/minio-dotnet/llms.txt Generates a presigned URL for temporary PUT access to upload an object. The URL is valid for a specified duration. Examples show usage with curl and HttpClient. ```csharp using Minio; var client = new MinioClientBuilder("http://localhost:9000") .WithStaticCredentials("minioadmin", "minioadmin") .Build(); // Generate upload URL valid for 30 minutes Uri uploadUrl = await client.PresignedPutObjectAsync( "my-bucket", "uploads/user-file.txt", TimeSpan.FromMinutes(30) ); Console.WriteLine($"Upload URL: {uploadUrl}"); // Client can upload using the presigned URL with curl: // curl -X PUT -T "localfile.txt" "https://presigned-url..." // Or programmatically with HttpClient: using var httpClient = new HttpClient(); using var content = new ByteArrayContent(System.Text.Encoding.UTF8.GetBytes("File content")); var response = await httpClient.PutAsync(uploadUrl, content); Console.WriteLine($"Upload status: {response.StatusCode}"); ``` -------------------------------- ### Retrieve Object Metadata with HeadObjectAsync Source: https://context7.com/minio/minio-dotnet/llms.txt Use HeadObjectAsync to get an object's metadata without downloading its content. Ensure the MinIO client is configured with endpoint and credentials. ```csharp using Minio; var client = new MinioClientBuilder("http://localhost:9000") .WithStaticCredentials("minioadmin", "minioadmin") .Build(); var info = await client.HeadObjectAsync("my-bucket", "documents/report.pdf"); Console.WriteLine($"Key: {info.Key}"); Console.WriteLine($"Size: {info.ContentLength} bytes"); Console.WriteLine($"Content-Type: {info.ContentType}"); Console.WriteLine($"Last Modified: {info.LastModified}"); Console.WriteLine($"ETag: {info.Etag}"); Console.WriteLine($"Version ID: {info.VersionId}"); // Access user metadata foreach (var (key, value) in info.UserMetadata) { Console.WriteLine($"Metadata [{key}]: {value}"); } ``` -------------------------------- ### Create a Bucket Source: https://context7.com/minio/minio-dotnet/llms.txt Initialize a new bucket. Object Lock must be enabled at creation if required. ```csharp using Minio; var client = new MinioClientBuilder("http://localhost:9000") .WithStaticCredentials("minioadmin", "minioadmin") .Build(); // Create a simple bucket string location = await client.CreateBucketAsync("my-bucket"); Console.WriteLine($"Bucket created at: {location}"); // Output: Bucket created at: /my-bucket // Create bucket with Object Lock enabled (for immutable storage) string lockBucketLocation = await client.CreateBucketAsync( bucketName: "immutable-bucket", objectLocking: true, region: "us-east-1" ); ``` -------------------------------- ### Build and Test MinIO .NET SDK Source: https://github.com/minio/minio-dotnet/blob/master/CLAUDE.md Commands for building the SDK, running unit tests, and executing integration tests. Integration tests require Docker. ```bash dotnet build ``` ```bash dotnet test Minio.UnitTests ``` ```bash dotnet test Minio.UnitTests --filter "FullyQualifiedName~TestMethodName" ``` ```bash dotnet test Minio.IntegrationTests ``` -------------------------------- ### Construct MinIO Client with MinioClientBuilder Source: https://context7.com/minio/minio-dotnet/llms.txt Use the fluent API to instantiate an IMinioClient directly. Supports static credentials, environment variables, and custom regions. ```csharp using Minio; using Minio.Model; // Create client with static credentials var client = new MinioClientBuilder("http://localhost:9000") .WithStaticCredentials("minioadmin", "minioadmin") .Build(); // Create client with custom region var clientWithRegion = new MinioClientBuilder("https://s3.eu-west-1.amazonaws.com") .WithRegion("eu-west-1") .WithStaticCredentials("accessKey", "secretKey", sessionToken: null) .Build(); // Create client using environment credentials (MINIO_ROOT_USER, MINIO_ROOT_PASSWORD) var envClient = new MinioClientBuilder("http://localhost:9000") .WithEnvironmentCredentials() .Build(); ``` -------------------------------- ### Create MinIO Client Directly Source: https://github.com/minio/minio-dotnet/blob/master/CLAUDE.md Instantiates the MinIO client using a direct builder pattern. Requires the endpoint URL and static credentials. ```csharp var client = new MinioClientBuilder("https://minio.example.com") .WithStaticCredentials("accessKey", "secretKey") .Build(); ``` -------------------------------- ### Enable and Query Bucket Versioning Source: https://context7.com/minio/minio-dotnet/llms.txt Use this to enable, suspend, or query the versioning status of a bucket. Ensure the bucket exists before calling these methods. ```csharp using Minio; using Minio.Model; var client = new MinioClientBuilder("http://localhost:9000") .WithStaticCredentials("minioadmin", "minioadmin") .Build(); // Enable versioning await client.SetBucketVersioningAsync("my-bucket", VersioningStatus.Enabled); Console.WriteLine("Versioning enabled"); // Check versioning status var config = await client.GetBucketVersioningAsync("my-bucket"); Console.WriteLine($"Versioning status: {config.Status}"); Console.WriteLine($"MFA Delete: {config.MfaDelete}"); // Suspend versioning (existing versions are preserved) await client.SetBucketVersioningAsync("my-bucket", VersioningStatus.Suspended); ``` -------------------------------- ### Configure MinIO Client with Dependency Injection Source: https://github.com/minio/minio-dotnet/blob/master/CLAUDE.md Configures the MinIO client for use with dependency injection. This method requires the endpoint URL and static credentials. ```csharp services .AddMinio("http://localhost:9000") .WithStaticCredentials("minioadmin", "minioadmin"); ``` -------------------------------- ### Execute S3 Select Queries with MinIO .NET SDK Source: https://context7.com/minio/minio-dotnet/llms.txt Demonstrates how to execute SQL queries on CSV, JSON, and Parquet objects using S3 Select. Requires specifying input and output serialization formats. ```csharp using Minio; using Minio.Model; var client = new MinioClientBuilder("http://localhost:9000") .WithStaticCredentials("minioadmin", "minioadmin") .Build(); // Query CSV file var csvOptions = new SelectObjectOptions { Expression = "SELECT name, age FROM s3object WHERE age > 30", InputSerialization = new CsvInput { FileHeaderInfo = CsvFileHeaderInfo.Use, FieldDelimiter = ",", RecordDelimiter = "\n" }, OutputSerialization = new CsvOutput { FieldDelimiter = ",", RecordDelimiter = "\n" } }; Console.WriteLine("Query results (CSV):"); await foreach (var record in client.SelectObjectContentAsync("my-bucket", "data.csv", csvOptions)) { Console.Write(record); } // Query JSON file var jsonOptions = new SelectObjectOptions { Expression = "SELECT s.name, s.email FROM s3object s WHERE s.status = 'active'", InputSerialization = new JsonInput { Type = JsonType.Lines }, OutputSerialization = new JsonOutput { RecordDelimiter = "\n" } }; Console.WriteLine("\nQuery results (JSON):"); await foreach (var record in client.SelectObjectContentAsync("my-bucket", "users.json", jsonOptions)) { Console.WriteLine(record); } // Query Parquet file var parquetOptions = new SelectObjectOptions { Expression = "SELECT * FROM s3object LIMIT 100", InputSerialization = new ParquetInput(), OutputSerialization = new JsonOutput() }; await foreach (var record in client.SelectObjectContentAsync("my-bucket", "data.parquet", parquetOptions)) { Console.WriteLine(record); } ``` -------------------------------- ### Register MinIO Client with Dependency Injection Source: https://context7.com/minio/minio-dotnet/llms.txt Integrate MinIO into ASP.NET Core or generic host applications using IServiceCollection extensions. ```csharp using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Minio; var builder = Host.CreateApplicationBuilder(args); // Register MinIO with static credentials builder.Services .AddMinio("http://localhost:9000") .WithStaticCredentials("minioadmin", "minioadmin"); // Or use environment credentials builder.Services .AddMinio("http://localhost:9000") .WithEnvironmentCredentials(); // Or configure via options delegate builder.Services .AddMinio(opts => { opts.EndPoint = new Uri("https://minio.example.com"); opts.Region = "us-east-1"; }) .WithStaticCredentials(opts => { opts.AccessKey = "accessKey"; opts.SecretKey = "secretKey"; }); using var host = builder.Build(); var minioClient = host.Services.GetRequiredService(); ``` -------------------------------- ### Check Bucket Existence Source: https://context7.com/minio/minio-dotnet/llms.txt Verify if a bucket exists and is accessible with current credentials. ```csharp using Minio; var client = new MinioClientBuilder("http://localhost:9000") .WithStaticCredentials("minioadmin", "minioadmin") .Build(); bool exists = await client.BucketExistsAsync("my-bucket"); if (!exists) { await client.CreateBucketAsync("my-bucket"); Console.WriteLine("Bucket created"); } else { Console.WriteLine("Bucket already exists"); } ``` -------------------------------- ### Configure Object Lock and Retention Source: https://context7.com/minio/minio-dotnet/llms.txt Set up object locking for WORM compliance. Buckets must be created with object locking enabled. Default retention rules can be set at the bucket level, and specific retention or legal holds can be applied to individual objects. ```csharp using Minio; using Minio.Model; var client = new MinioClientBuilder("http://localhost:9000") .WithStaticCredentials("minioadmin", "minioadmin") .Build(); // Create bucket with Object Lock enabled (required at creation time) await client.CreateBucketAsync("compliance-bucket", objectLocking: true); // Set default retention rule for the bucket var retentionRule = new RetentionRule { Mode = RetentionMode.Governance, Days = 90 // Retain for 90 days }; await client.SetObjectLockConfigurationAsync("compliance-bucket", retentionRule); // Get current lock configuration var lockConfig = await client.GetObjectLockConfigurationAsync("compliance-bucket"); Console.WriteLine($"Lock enabled: {lockConfig.ObjectLockEnabled}"); Console.WriteLine($"Default mode: {lockConfig.Rule?.DefaultRetention?.Mode}"); // Set retention on specific object var retention = new ObjectRetention { Mode = RetentionMode.Compliance, RetainUntilDate = DateTimeOffset.UtcNow.AddYears(7) }; await client.SetObjectRetentionAsync("compliance-bucket", "financial-report.pdf", retention); // Set legal hold on object await client.SetObjectLegalHoldAsync("compliance-bucket", "legal-doc.pdf", LegalHoldStatus.On); // Check legal hold status var holdStatus = await client.GetObjectLegalHoldAsync("compliance-bucket", "legal-doc.pdf"); Console.WriteLine($"Legal hold: {holdStatus}"); ``` -------------------------------- ### Configure Bucket Notifications with C# Source: https://context7.com/minio/minio-dotnet/llms.txt Configures bucket notifications to send events to Lambda, SNS topics, or SQS queues. Allows setting event types and filters for each notification target. Includes retrieving current configuration. ```csharp using Minio; using Minio.Model; var client = new MinioClientBuilder("http://localhost:9000") .WithStaticCredentials("minioadmin", "minioadmin") .Build(); var notification = new BucketNotification(); // Add SQS queue notification notification.QueueConfigs.Add(new QueueConfig { Queue = "arn:minio:sqs::primary:webhook", Id = "image-uploads", Events = { EventType.ObjectCreatedAll }, Filter = { ["prefix"] = "images/", ["suffix"] = ".jpg" } }); // Add SNS topic notification notification.TopicConfigs.Add(new TopicConfig { Topic = "arn:minio:sns::primary:kafka", Id = "all-deletes", Events = { EventType.ObjectRemovedAll } }); // Add Lambda notification notification.LambdaConfigs.Add(new LambdaConfig { Lambda = "arn:minio:lambda::primary:function", Id = "process-uploads", Events = { EventType.ObjectCreatedPut } }); await client.SetBucketNotificationsAsync("my-bucket", notification); Console.WriteLine("Notifications configured"); // Retrieve current configuration var current = await client.GetBucketNotificationsAsync("my-bucket"); Console.WriteLine($"Queue configs: {current.QueueConfigs.Count}"); Console.WriteLine($"Topic configs: {current.TopicConfigs.Count}"); Console.WriteLine($"Lambda configs: {current.LambdaConfigs.Count}"); ``` -------------------------------- ### Listen to Bucket Notifications with C# Source: https://context7.com/minio/minio-dotnet/llms.txt Subscribes to real-time bucket notifications using MinIO's listen endpoint, returning an IObservable stream of NotificationEvent. Supports filtering by event type, prefix, and suffix. ```csharp using Minio; using Minio.Model; var client = new MinioClientBuilder("http://localhost:9000") .WithStaticCredentials("minioadmin", "minioadmin") .Build(); // Subscribe to all object events var observable = await client.ListenBucketNotificationsAsync( "my-bucket", new[] { EventType.ObjectCreatedAll, EventType.ObjectRemovedAll } ); using var subscription = observable.Subscribe( onNext: evt => { Console.WriteLine($"Event: {evt.EventName}"); Console.WriteLine($" Bucket: {evt.S3.Bucket.Name}"); Console.WriteLine($" Key: {evt.S3.Object.Key}"); Console.WriteLine($" Size: {evt.S3.Object.Size}"); Console.WriteLine($" Time: {evt.EventTime}"); }, onError: ex => Console.WriteLine($"Error: {ex.Message}"), onCompleted: () => Console.WriteLine("Stream completed") ); // Subscribe with prefix/suffix filter var imageObservable = await client.ListenBucketNotificationsAsync( "my-bucket", new[] { EventType.ObjectCreatedPut }, prefix: "images/", suffix: ".jpg" ); // Keep listening until cancellation Console.WriteLine("Listening for events... Press Enter to stop."); Console.ReadLine(); ``` -------------------------------- ### CreateBucketAsync Source: https://context7.com/minio/minio-dotnet/llms.txt Creates a new bucket with specified name, optional object locking, and region. ```APIDOC ## POST /minio/CreateBucketAsync ### Description Creates a new bucket with the specified name. Optionally enable S3 Object Lock at creation time (cannot be added later) and specify a region. ### Method POST ### Endpoint `/minio/CreateBucketAsync` ### Parameters #### Query Parameters - **bucketName** (string) - Required - The name of the bucket to create. - **objectLocking** (bool) - Optional - Enables S3 Object Lock for the bucket. - **region** (string) - Optional - The region where the bucket will be created. ### Request Example ```csharp using Minio; var client = new MinioClientBuilder("http://localhost:9000") .WithStaticCredentials("minioadmin", "minioadmin") .Build(); // Create a simple bucket string location = await client.CreateBucketAsync("my-bucket"); Console.WriteLine($"Bucket created at: {location}"); // Output: Bucket created at: /my-bucket // Create bucket with Object Lock enabled (for immutable storage) string lockBucketLocation = await client.CreateBucketAsync( bucketName: "immutable-bucket", objectLocking: true, region: "us-east-1" ); ``` ### Response #### Success Response (200) - **location** (string) - The location where the bucket was created. ``` -------------------------------- ### ListBucketsAsync Source: https://context7.com/minio/minio-dotnet/llms.txt Lists all buckets accessible to the current credentials. ```APIDOC ## GET /minio/ListBucketsAsync ### Description Lists all buckets accessible to the current credentials. Returns an `IAsyncEnumerable` for efficient streaming. ### Method GET ### Endpoint `/minio/ListBucketsAsync` ### Parameters None ### Request Example ```csharp using Minio; var client = new MinioClientBuilder("http://localhost:9000") .WithStaticCredentials("minioadmin", "minioadmin") .Build(); Console.WriteLine("Available buckets:"); await foreach (var bucket in client.ListBucketsAsync()) { Console.WriteLine($" {bucket.Name} (created: {bucket.CreationDate:yyyy-MM-dd HH:mm:ss})"); } // Output: // my-bucket (created: 2024-01-15 10:30:00) // backup-bucket (created: 2024-01-10 08:15:00) ``` ### Response #### Success Response (200) - **buckets** (IAsyncEnumerable) - A stream of `BucketInfo` objects, each containing bucket name and creation date. ``` -------------------------------- ### Initiate Multipart Upload Source: https://context7.com/minio/minio-dotnet/llms.txt Initiates a multipart upload for large files, returning an UploadId. This is the first step in uploading large objects in parts. ```csharp using System.Net.Http.Headers; using Minio; using Minio.Model; var client = new MinioClientBuilder("http://localhost:9000") .WithStaticCredentials("minioadmin", "minioadmin") .Build(); const string bucket = "my-bucket"; const string key = "large-file.bin"; const int partSize = 5 * 1024 * 1024; // 5MB minimum part size // Step 1: Initiate multipart upload var createOptions = new CreateMultipartUploadOptions { ContentType = new MediaTypeHeaderValue("application/octet-stream") }; var createResult = await client.CreateMultipartUploadAsync(bucket, key, createOptions); string uploadId = createResult.UploadId; Console.WriteLine($"Upload ID: {uploadId}"); try { var parts = new List(); await using var fileStream = File.OpenRead("large-file.bin"); int partNumber = 1; var buffer = new byte[partSize]; // Step 2: Upload parts while (true) { int bytesRead = await fileStream.ReadAsync(buffer); if (bytesRead == 0) break; using var partStream = new MemoryStream(buffer, 0, bytesRead); var uploadResult = await client.UploadPartAsync( bucket, key, uploadId, partNumber, partStream, progress: (pos, len) => Console.WriteLine($"Part {partNumber}: {pos}/{len} bytes") ); parts.Add(new PartInfo { PartNumber = partNumber, ETag = uploadResult.ETag }); Console.WriteLine($"Uploaded part {partNumber}, ETag: {uploadResult.ETag}"); partNumber++; } // Step 3: Complete upload var completeResult = await client.CompleteMultipartUploadAsync(bucket, key, uploadId, parts); Console.WriteLine($"Upload complete! ETag: {completeResult.ETag}, Location: {completeResult.Location}"); } catch (Exception) { // Abort on failure to clean up uploaded parts await client.AbortMultipartUploadAsync(bucket, key, uploadId); throw; } ``` -------------------------------- ### PresignedPutObjectAsync Source: https://context7.com/minio/minio-dotnet/llms.txt Generates a presigned URL that grants temporary PUT access, allowing clients to upload an object directly to Minio without needing credentials. ```APIDOC ## POST /minio/minio-dotnet/PresignedPutObjectAsync ### Description Generates a presigned URL granting temporary PUT access to upload an object. ### Method POST (Implied by the nature of generating a URL for upload) ### Endpoint /minio/minio-dotnet/PresignedPutObjectAsync ### Parameters #### Query Parameters - **bucketName** (string) - Required - The name of the bucket. - **objectName** (string) - Required - The name of the object to upload. - **expiresIn** (TimeSpan) - Required - The duration for which the presigned URL will be valid. ### Request Example ```csharp var client = new MinioClientBuilder("http://localhost:9000") .WithStaticCredentials("minioadmin", "minioadmin") .Build(); Uri uploadUrl = await client.PresignedPutObjectAsync( "my-bucket", "uploads/user-file.txt", TimeSpan.FromMinutes(30) ); Console.WriteLine($"Upload URL: {uploadUrl}"); ``` ### Response #### Success Response (200) - **uploadUrl** (Uri) - The generated presigned URL for uploading the object. #### Response Example ``` https://localhost:9000/my-bucket/uploads/user-file.txt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=... ``` ``` -------------------------------- ### List All Buckets Source: https://context7.com/minio/minio-dotnet/llms.txt Retrieve a list of all accessible buckets using IAsyncEnumerable for efficient streaming. ```csharp using Minio; var client = new MinioClientBuilder("http://localhost:9000") .WithStaticCredentials("minioadmin", "minioadmin") .Build(); Console.WriteLine("Available buckets:"); await foreach (var bucket in client.ListBucketsAsync()) { Console.WriteLine($" {bucket.Name} (created: {bucket.CreationDate:yyyy-MM-dd HH:mm:ss})"); } // Output: // my-bucket (created: 2024-01-15 10:30:00) // backup-bucket (created: 2024-01-10 08:15:00) ``` -------------------------------- ### List Objects in a Bucket with ListObjectsAsync Source: https://context7.com/minio/minio-dotnet/llms.txt ListObjectsAsync streams objects efficiently. It supports filtering by prefix, delimiter for folder-like structures, pagination with pageSize, and including metadata. ```csharp using Minio; var client = new MinioClientBuilder("http://localhost:9000") .WithStaticCredentials("minioadmin", "minioadmin") .Build(); // List all objects Console.WriteLine("All objects:"); await foreach (var obj in client.ListObjectsAsync("my-bucket")) { Console.WriteLine($" {obj.Key,-40} {obj.Size,10} bytes {obj.LastModified:yyyy-MM-dd}"); } // List objects with prefix filter (like a folder) Console.WriteLine("\nObjects in 'images/' folder:"); await foreach (var obj in client.ListObjectsAsync("my-bucket", prefix: "images/")) { Console.WriteLine($" {obj.Key}"); } // List with delimiter (folder-like listing) Console.WriteLine("\nTop-level folders:"); await foreach (var obj in client.ListObjectsAsync("my-bucket", delimiter: "/", prefix: "")) { Console.WriteLine($" {obj.Key}"); } // List with pagination await foreach (var obj in client.ListObjectsAsync("my-bucket", prefix: "logs/", pageSize: 100)) { Console.WriteLine($" {obj.Key} ({obj.StorageClass})"); } // List with metadata (MinIO-specific) await foreach (var obj in client.ListObjectsAsync("my-bucket", includeMetadata: true)) { Console.WriteLine($" {obj.Key} - Type: {obj.ContentType}"); foreach (var meta in obj.UserMetadata) { Console.WriteLine($" {meta.Key}: {meta.Value}"); } } ``` -------------------------------- ### Manage Bucket Tags Source: https://context7.com/minio/minio-dotnet/llms.txt Apply, retrieve, and remove tags on buckets for organization and cost allocation. Tags are key-value pairs. ```csharp using Minio; var client = new MinioClientBuilder("http://localhost:9000") .WithStaticCredentials("minioadmin", "minioadmin") .Build(); // Set bucket tags var tags = new Dictionary { ["environment"] = "production", ["department"] = "engineering", ["cost-center"] = "12345" }; await client.SetBucketTaggingAsync("my-bucket", tags); // Get bucket tags var currentTags = await client.GetBucketTaggingAsync("my-bucket"); if (currentTags != null) { foreach (var (key, value) in currentTags) { Console.WriteLine($" {key}: {value}"); } } // Remove all tags await client.DeleteBucketTaggingAsync("my-bucket"); ``` -------------------------------- ### Upload Object Async Source: https://context7.com/minio/minio-dotnet/llms.txt Uploads an object, automatically selecting between single-part and multipart upload based on the stream size. Streams larger than 16 MiB will use multipart upload. ```csharp using System.Net.Http.Headers; using Minio; using Minio.Model; var client = new MinioClientBuilder("http://localhost:9000") .WithStaticCredentials("minioadmin", "minioadmin") .Build(); // Upload large file with automatic multipart handling await using var fileStream = File.OpenRead("large-video.mp4"); var options = new PutObjectOptions { ContentType = new MediaTypeHeaderValue("video/mp4"), StorageClass = "STANDARD" }; await client.UploadObjectAsync( "my-bucket", "videos/large-video.mp4", fileStream, options, progress: (position, length) => { if (length > 0) Console.WriteLine($"Uploaded {position / 1024 / 1024} MB of {length / 1024 / 1024} MB"); } ); ``` -------------------------------- ### PresignedPostPolicyAsync Source: https://context7.com/minio/minio-dotnet/llms.txt Generates a presigned POST policy, which is useful for browser-based multipart/form-data uploads directly to Minio without requiring server-side intervention for each upload. ```APIDOC ## POST /minio/minio-dotnet/PresignedPostPolicyAsync ### Description Generates a presigned POST policy for browser-based multipart/form-data uploads directly to S3 compatible storage. ### Method POST (Implied by the nature of generating a policy for upload) ### Endpoint /minio/minio-dotnet/PresignedPostPolicyAsync ### Parameters #### Path Parameters - **bucketName** (string) - Required - The name of the bucket. - **objectName** (string) - Required - The object name, can include placeholders like `${filename}`. - **expiresIn** (TimeSpan) - Required - The duration for which the presigned POST policy will be valid. #### Request Body - **conditions** (List) - Optional - A list of conditions that must be met for the upload, such as content length or content type. - **condition** (object) - Represents a single condition. - **Type** (string) - The type of condition (e.g., "content-length-range", "starts-with"). - **Value** (string or array) - The value(s) for the condition. ### Request Example ```csharp var client = new MinioClientBuilder("http://localhost:9000") .WithStaticCredentials("minioadmin", "minioadmin") .Build(); var conditions = new List { PostPolicyCondition.ContentLengthRange(1, 10 * 1024 * 1024), // 1 byte to 10MB PostPolicyCondition.StartsWith("Content-Type", "image/") // Only images }; var result = await client.PresignedPostPolicyAsync( "my-bucket", "uploads/${filename}", TimeSpan.FromHours(1), conditions ); Console.WriteLine($"Upload URL: {result.Url}"); Console.WriteLine("Form fields:"); foreach (var (key, value) in result.FormData) { Console.WriteLine($" {key}: {value}"); } ``` ### Response #### Success Response (200) - **Url** (string) - The URL to which the form should be posted. - **FormData** (Dictionary) - A dictionary of form fields that must be included in the POST request. #### Response Example ```json { "Url": "https://localhost:9000/my-bucket", "FormData": { "key": "uploads/${filename}", "AWSAccessKeyId": "minioadmin", "policy": "ey...", "signature": "..." } } ``` ``` -------------------------------- ### Copy Object Server-Side Source: https://context7.com/minio/minio-dotnet/llms.txt Copies an object from a source to a destination bucket and key on the server without downloading the content. Supports options for metadata replacement, content type, user metadata, and specific version IDs. ```csharp using System.Net.Http.Headers; using Minio; using Minio.Model; var client = new MinioClientBuilder("http://localhost:9000") .WithStaticCredentials("minioadmin", "minioadmin") .Build(); // Simple copy var result = await client.CopyObjectAsync( destBucketName: "backup-bucket", destKey: "archive/file.txt", srcBucketName: "my-bucket", srcKey: "file.txt" ); Console.WriteLine($"Copied to: {result.Location}, ETag: {result.ETag}"); // Copy with modified metadata var options = new CopyObjectOptions { MetadataDirective = MetadataDirective.Replace, ContentType = new MediaTypeHeaderValue("text/plain"), UserMetadata = new Dictionary { ["copied-from"] = "my-bucket", ["copy-date"] = DateTime.UtcNow.ToString("O") } }; await client.CopyObjectAsync("backup-bucket", "renamed.txt", "my-bucket", "original.txt", options); // Copy specific version var versionOptions = new CopyObjectOptions { SourceVersionId = "abc123-version-id" }; await client.CopyObjectAsync("backup-bucket", "versioned-copy.txt", "my-bucket", "file.txt", versionOptions); ``` -------------------------------- ### POST /bucket/delete Source: https://context7.com/minio/minio-dotnet/llms.txt Batch delete multiple objects in a single request. ```APIDOC ## POST /bucket/delete ### Description Batch delete multiple objects in a single request. Use DeleteObjectsVerboseAsync to receive per-object success/error results. ### Method POST ### Endpoint /{bucket} ### Parameters #### Path Parameters - **bucket** (string) - Required - The name of the bucket. #### Request Body - **objectsToDelete** (List) - Required - List of objects to delete, including Key and optional VersionId. ``` -------------------------------- ### Batch Delete Objects with DeleteObjectsAsync and DeleteObjectsVerboseAsync Source: https://context7.com/minio/minio-dotnet/llms.txt DeleteObjectsAsync performs a silent batch delete, while DeleteObjectsVerboseAsync provides per-object success or error results. Both require a list of ObjectIdentifier objects. ```csharp using Minio; using Minio.Model; var client = new MinioClientBuilder("http://localhost:9000") .WithStaticCredentials("minioadmin", "minioadmin") .Build(); // Collect objects to delete var objectsToDelete = new List(); await foreach (var obj in client.ListObjectsAsync("my-bucket", prefix: "temp/")) { objectsToDelete.Add(new ObjectIdentifier { Key = obj.Key }); } // Batch delete (silent mode - errors are ignored) await client.DeleteObjectsAsync("my-bucket", objectsToDelete); Console.WriteLine($"Deleted {objectsToDelete.Count} objects"); // Batch delete with verbose results var deleteItems = new List { new() { Key = "file1.txt" }, new() { Key = "file2.txt", VersionId = "version-123" }, new() { Key = "file3.txt" } }; await foreach (var result in client.DeleteObjectsVerboseAsync("my-bucket", deleteItems)) { if (result.IsSuccess) Console.WriteLine($"Deleted: {result.Key}"); else Console.WriteLine($"Failed: {result.Key} - {result.ErrorCode}: {result.ErrorMessage}"); } ``` -------------------------------- ### Bucket Versioning API Source: https://context7.com/minio/minio-dotnet/llms.txt Enable, suspend, or query versioning on a bucket to maintain multiple versions of objects. ```APIDOC ## Bucket Versioning API ### Description Enable, suspend, or query versioning on a bucket to maintain multiple versions of objects. ### Method POST, GET ### Endpoint `/minio/minio-dotnet/blob/main/Examples/Bucket/SetBucketVersioningAsync.cs` `/minio/minio-dotnet/blob/main/Examples/Bucket/GetBucketVersioningAsync.cs` ### Request Body (for enabling/suspending) - **bucketName** (string) - Required - The name of the bucket. - **versioningStatus** (VersioningStatus) - Required - The desired versioning status (Enabled or Suspended). ### Response (for getting status) - **Status** (VersioningStatus) - The current versioning status of the bucket. - **MfaDelete** (bool) - Indicates if MFA Delete is enabled. ``` -------------------------------- ### Bucket Encryption API Source: https://context7.com/minio/minio-dotnet/llms.txt Configure server-side encryption defaults for a bucket using SSE-S3 or SSE-KMS. ```APIDOC ## PUT/GET/DELETE BucketEncryption ### Description Manage server-side encryption defaults for a bucket. ### Methods - **PUT**: SetBucketEncryptionAsync - **GET**: GetBucketEncryptionAsync - **DELETE**: RemoveBucketEncryptionAsync ### Parameters #### Path Parameters - **bucketName** (string) - Required - The name of the bucket. #### Request Body (for PUT) - **Rules** (list) - Required - List of ServerSideEncryptionRule objects. ```