### MinioClient Initialization Source: https://github.com/minio/minio-java/blob/master/_autodocs/01-minio-client.md Demonstrates how to create a MinioClient instance using the builder pattern. This is the primary way to get started with the client. ```APIDOC ## MinioClient Initialization ### Description Initializes a `MinioClient` instance using its builder. ### Method `public static Builder builder()` ### Returns `Builder` - A new builder instance for configuring `MinioClient`. ### Example ```java MinioClient minioClient = MinioClient.builder() .endpoint("https://play.min.io") .credentials("accessKey", "secretKey") .build(); ``` ``` -------------------------------- ### Quick Start File Uploader Example Source: https://github.com/minio/minio-java/blob/master/README.md This Java code connects to an object storage server, creates a bucket if it doesn't exist, and uploads a file. It uses the MinIO server playground for demonstration. ```java import io.minio.BucketExistsArgs; import io.minio.MakeBucketArgs; import io.minio.MinioClient; import io.minio.UploadObjectArgs; import io.minio.errors.MinioException; import java.io.IOException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; public class FileUploader { public static void main(String[] args) throws IOException, NoSuchAlgorithmException, InvalidKeyException { try { // Create a minioClient with the MinIO server playground, its access key and secret key. MinioClient minioClient = MinioClient.builder() .endpoint("https://play.min.io") .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG") .build(); // Make 'asiatrip' bucket if not exist. boolean found = minioClient.bucketExists(BucketExistsArgs.builder().bucket("asiatrip").build()); if (!found) { // Make a new bucket called 'asiatrip'. minioClient.makeBucket(MakeBucketArgs.builder().bucket("asiatrip").build()); } else { System.out.println("Bucket 'asiatrip' already exists."); } // Upload '/home/user/Photos/asiaphotos.zip' as object name 'asiaphotos-2015.zip' to bucket // 'asiatrip'. minioClient.uploadObject( UploadObjectArgs.builder() .bucket("asiatrip") .object("asiaphotos-2015.zip") .filename("/home/user/Photos/asiaphotos.zip") .build()); System.out.println( "'/home/user/Photos/asiaphotos.zip' is successfully uploaded as " + "object 'asiaphotos-2015.zip' to bucket 'asiatrip'."); } catch (MinioException e) { System.out.println("Error occurred: " + e); System.out.println("HTTP trace: " + e.httpTrace()); } } } ``` -------------------------------- ### Generate Presigned Object URLs in Java Source: https://github.com/minio/minio-java/blob/master/docs/API.md Use these examples to generate presigned URLs for GET, PUT, and HEAD operations with custom expiration times and optional query parameters. ```java // Get presigned URL string to download 'my-objectname' in 'my-bucketname' // with an expiration of 2 hours. // // Additionally also add 'response-content-type' to dynamically set content-type // for the server response. Map reqParams = new HashMap(); reqParams.put("response-content-type", "application/json"); String url = minioClient.getPresignedObjectUrl( GetPresignedObjectUrlArgs.builder() .method(Method.GET) .bucket("my-bucketname") .object("my-objectname") .expiry(2, TimeUnit.HOURS) .extraQueryParams(reqParams) .build()); System.out.println(url); // Get presigned URL string to upload 'my-objectname' in 'my-bucketname' // with an expiration of 1 day. String url = minioClient.getPresignedObjectUrl( GetPresignedObjectUrlArgs.builder() .method(Method.PUT) .bucket("my-bucketname") .object("my-objectname") .expiry(1, TimeUnit.DAYS) .build()); System.out.println(url); // Get presigned URL string to lookup metadata for 'my-objectname' in 'my-bucketname' // with an expiration of 2 hours. // // Additionally also add 'response-content-type' to dynamically set content-type // for the server metadata response. Map reqParams = new HashMap(); reqParams.put("response-content-type", "application/json"); String url = minioClient.getPresignedObjectUrl( GetPresignedObjectUrlArgs.builder() .method(Method.HEAD) .bucket("my-bucketname") .object("my-objectname") .expiry(2, TimeUnit.HOURS) .extraQueryParams(reqParams) .build()); System.out.println(url); ``` -------------------------------- ### Download Object Directly to File Source: https://github.com/minio/minio-java/blob/master/_autodocs/02-args-and-responses.md Example of downloading an object directly to a specified file path on the local filesystem. ```java minioClient.downloadObject( DownloadObjectArgs.builder() .bucket("my-bucket") .object("data/report.pdf") .filename("/tmp/report.pdf") .build()); ``` -------------------------------- ### Handling MinioException Source: https://github.com/minio/minio-java/blob/master/_autodocs/04-errors.md Example of how to catch and handle MinioException, including printing the error message and the HTTP trace if available. ```java try { minioClient.putObject(...); } catch (MinioException e) { System.err.println("Error: " + e.getMessage()); if (e.httpTrace() != null) { System.err.println("HTTP Trace:\n" + e.httpTrace()); } } ``` -------------------------------- ### Get Server Information Source: https://github.com/minio/minio-java/blob/master/_autodocs/06-admin-client.md Fetches comprehensive details about the MinIO server, including its version, uptime, and storage configuration. ```java GetServerInfoResponse serverInfo = adminClient.getServerInfo(); System.out.println("Version: " + serverInfo.serverVersion()); System.out.println("Region: " + serverInfo.region()); System.out.println("Storage: " + serverInfo.storageInfo()); ``` -------------------------------- ### Upload Object Using Presigned POST Source: https://github.com/minio/minio-java/blob/master/docs/API.md This example demonstrates how to construct and execute an HTTP POST request to upload an object using the form-data obtained from a presigned policy. Ensure the 'file' part is added last. ```java // Create new post policy for 'my-bucketname' with 7 days expiry from now. PostPolicy policy = new PostPolicy("my-bucketname", ZonedDateTime.now().plusDays(7)); // Add condition that 'key' (object name) equals to 'my-objectname'. policy.addEqualsCondition("key", "my-objectname"); // Add condition that 'Content-Type' starts with 'image/'. policy.addStartsWithCondition("Content-Type", "image/"); // Add condition that 'content-length-range' is between 64kiB to 10MiB. policy.addContentLengthRangeCondition(64 * 1024, 10 * 1024 * 1024); Map formData = minioClient.getPresignedPostFormData(policy); // Upload an image using POST object with form-data. MultipartBody.Builder multipartBuilder = new MultipartBody.Builder(); multipartBuilder.setType(MultipartBody.FORM); for (Map.Entry entry : formData.entrySet()) { multipartBuilder.addFormDataPart(entry.getKey(), entry.getValue()); } multipartBuilder.addFormDataPart("key", "my-objectname"); multipartBuilder.addFormDataPart("Content-Type", "image/png"); // "file" must be added at last. multipartBuilder.addFormDataPart( "file", "my-objectname", RequestBody.create(new File("Pictures/avatar.png"), null)); Request request = new Request.Builder() .url("https://play.min.io/my-bucketname") .post(multipartBuilder.build()) .build(); OkHttpClient httpClient = new OkHttpClient().newBuilder().build(); Response response = httpClient.newCall(request).execute(); if (response.isSuccessful()) { System.out.println("Pictures/avatar.png is uploaded successfully using POST object"); } else { System.out.println("Failed to upload Pictures/avatar.png"); } ``` -------------------------------- ### Configure HTTP Client with Increased Timeouts and SSL Source: https://github.com/minio/minio-java/blob/master/_autodocs/05-configuration-and-credentials.md Example of configuring an OkHttpClient with increased timeouts for large files and disabling SSL verification for self-signed certificates. Disabling SSL verification is not recommended for production environments. ```java // Increase timeouts for large files OkHttpClient.Builder builder = new OkHttpClient.Builder(); builder.connectTimeout(60, TimeUnit.SECONDS); builder.readTimeout(60, TimeUnit.SECONDS); builder.writeTimeout(60, TimeUnit.SECONDS); // Disable SSL verification (not recommended for production) SSLContext sslContext = SSLContext.getInstance("TLS"); sslContext.init(null, trustAllCerts, new java.security.SecureRandom()); builder.sslSocketFactory( sslContext.getSocketFactory(), (X509TrustManager) trustAllCerts[0]); builder.hostnameVerifier((hostname, session) -> true); MinioClient client = MinioClient.builder() .endpoint("https://self-signed.example.com") .credentials(key, secret) .httpClient(builder.build()) .build(); ``` -------------------------------- ### Set and Get Bucket Replication Source: https://github.com/minio/minio-java/blob/master/_autodocs/07-advanced-operations.md Configure cross-region replication for a bucket and retrieve the current replication configuration. ```java ReplicationConfiguration config = new ReplicationConfiguration(); // Build replication rules... minioClient.setBucketReplication( SetBucketReplicationArgs.builder() .bucket("my-bucket") .config(config) .build()); ReplicationConfiguration current = minioClient.getBucketReplication( GetBucketReplicationArgs.builder() .bucket("my-bucket") .build()); ``` -------------------------------- ### Upload Object from File Path Source: https://github.com/minio/minio-java/blob/master/_autodocs/02-args-and-responses.md Example of uploading an object from a local file path. The content type is auto-detected if not specified. ```java minioClient.uploadObject( UploadObjectArgs.builder() .bucket("my-bucket") .object("archive/backup.tar.gz") .filename("/path/to/backup.tar.gz") .build()); ``` -------------------------------- ### Custom Database Credential Provider Implementation Source: https://github.com/minio/minio-java/blob/master/_autodocs/05-configuration-and-credentials.md Implement the `Provider` interface to fetch credentials from custom sources like a database. This example shows fetching from a hypothetical database. ```java import io.minio.credentials.Provider; import io.minio.credentials.Credentials; public class DatabaseCredentialsProvider implements Provider { @Override public Credentials fetch() { // Fetch credentials from database, vault, custom service, etc. String accessKey = fetchFromDatabase("access_key"); String secretKey = fetchFromDatabase("secret_key"); return new Credentials(accessKey, secretKey, null, null); } private String fetchFromDatabase(String key) { // Database query here return null; } } // Usage MinioClient client = MinioClient.builder() .endpoint("https://s3.example.com") .credentialsProvider(new DatabaseCredentialsProvider()) .build(); ``` -------------------------------- ### Get Bucket Versioning Configuration - Java Source: https://github.com/minio/minio-java/blob/master/docs/API.md Fetches the versioning configuration for a bucket. The bucket name is a required argument. ```java VersioningConfiguration config = minioClient.getBucketVersioning(GetBucketVersioningArgs.builder().bucket("my-bucketname").build()); ``` -------------------------------- ### Get Bucket Replication Configuration - Java Source: https://github.com/minio/minio-java/blob/master/docs/API.md Fetches the replication configuration for a given bucket. Ensure the bucket name is correctly provided. ```java ReplicationConfiguration config = minioClient.getBucketReplication(GetBucketReplicationArgs.builder().bucket("my-bucketname").build()); ``` -------------------------------- ### Create MinioClient for AWS S3 (Anonymous Access) Source: https://github.com/minio/minio-java/blob/master/docs/API.md Use these examples to create a MinioClient for anonymous access to AWS S3. Supports endpoint configuration via String, URL, or HttpUrl objects. ```java // 1. Create client to S3 service 's3.amazonaws.com' at port 443 with TLS security // for anonymous access. MinioClient s3Client = MinioClient.builder().endpoint("https://s3.amazonaws.com").build(); ``` ```java // 2. Create client to S3 service 's3.amazonaws.com' at port 443 with TLS security // using URL object for anonymous access. MinioClient s3Client = MinioClient.builder().endpoint(new URL("https://s3.amazonaws.com")).build(); ``` ```java // 3. Create client to S3 service 's3.amazonaws.com' at port 9000 with TLS security // using okhttp3.HttpUrl object for anonymous access. MinioClient s3Client = MinioClient.builder().endpoint(HttpUrl.parse("https://s3.amazonaws.com")).build(); ``` -------------------------------- ### Set Object Tags Source: https://github.com/minio/minio-java/blob/master/_autodocs/03-types-and-enums.md Use Tags to set object and bucket metadata. This example demonstrates adding 'environment' and 'application' tags to an object. ```java Tags tags = new Tags(); tags.getTagMap().put("environment", "production"); tags.getTagMap().put("application", "api"); minioClient.setObjectTags( SetObjectTagsArgs.builder() .bucket("my-bucket") .object("my-object") .tags(tags) .build()); ``` -------------------------------- ### Manage Bucket Policies Source: https://github.com/minio/minio-java/blob/master/_autodocs/01-minio-client.md Set, get, or delete bucket access policies using JSON policy strings. Requires bucket name and policy configuration. ```java // Set policy String policyJson = "{\"Version\":\"2012-10-17\",...}"; minioClient.setBucketPolicy( SetBucketPolicyArgs.builder() .bucket("my-bucket") .policy(policyJson) .build()); // Get policy String policy = minioClient.getBucketPolicy( GetBucketPolicyArgs.builder().bucket("my-bucket").build()); // Delete policy minioClient.deleteBucketPolicy( DeleteBucketPolicyArgs.builder().bucket("my-bucket").build()); ``` -------------------------------- ### Minio Client Initialization with Try-with-Resources Source: https://github.com/minio/minio-java/blob/master/_autodocs/08-usage-patterns.md Recommended pattern for initializing and using the Minio client within a try-with-resources block to ensure automatic closing of the client and its resources. ```java try (MinioClient minioClient = MinioClient.builder() .endpoint("https://s3.amazonaws.com") .credentials(key, secret) .build()) { // Use client minioClient.listBuckets(); } // Auto-closed ``` -------------------------------- ### Generate Presigned GET Object URL Source: https://github.com/minio/minio-java/blob/master/_autodocs/01-minio-client.md Generates a presigned URL for temporary GET access to an object. Specify the bucket, object name, and desired expiration time. ```java String url = minioClient.getPresignedObjectUrl( GetPresignedObjectUrlArgs.builder() .method(io.minio.http.Method.GET) .bucket("my-bucket") .object("my-object") .expiration(2, java.util.concurrent.TimeUnit.HOURS) .build()); ``` -------------------------------- ### Initialize and Use MinioClient with Try-with-Resources Source: https://github.com/minio/minio-java/blob/master/_autodocs/01-minio-client.md Demonstrates how to create a MinioClient instance using builder pattern and utilize it within a try-with-resources block for automatic resource management. Ensure the endpoint, access key, and secret key are correctly configured. ```java try (MinioClient minioClient = MinioClient.builder() .endpoint("https://play.min.io") .credentials("key", "secret") .build()) { // Use client } // Auto-closed ``` -------------------------------- ### GET /getObject Source: https://github.com/minio/minio-java/blob/master/docs/API.md Retrieves the data of an object as an InputStream. ```APIDOC ## GET /getObject ### Description Gets data of an object. Returned InputStream must be closed after use to release network resources. ### Parameters #### Request Body - **args** (GetObjectArgs) - Required - Arguments including bucket, object, offset, length, and ssec settings. ### Response #### Success Response (200) - **InputStream** - Contains object data. ### Response Example ```java try (InputStream stream = minioClient.getObject( GetObjectArgs.builder() .bucket("my-bucketname") .object("my-objectname") .build())) { // Read data from stream }``` ``` -------------------------------- ### Configure MinioClient with Full Options Source: https://github.com/minio/minio-java/blob/master/_autodocs/01-minio-client.md Initialize MinioClient with a full set of configuration options including endpoint, region, and credentials. ```java MinioClient minioClient = MinioClient.builder() .endpoint("https://s3.amazonaws.com") .region("us-east-1") .credentials("AKIAIOSFODNN7EXAMPLE", "wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY") .build(); ``` -------------------------------- ### Initialize Minio Client with Static Credentials Source: https://github.com/minio/minio-java/blob/master/_autodocs/README.md Initializes the MinioClient using static endpoint and credentials. Ensure to replace placeholder credentials with your actual ones. ```java import io.minio.MinioClient; MinioClient minioClient = MinioClient.builder() .endpoint("https://s3.amazonaws.com") .credentials("AKIAIOSFODNN7EXAMPLE", "wJalrXUtnFEMI/...") .build(); ``` -------------------------------- ### GET /getObjectAcl Source: https://github.com/minio/minio-java/blob/master/docs/API.md Retrieves the access control policy for an object. ```APIDOC ## GET /getObjectAcl ### Description Gets tags/ACL of an object. ### Parameters #### Request Body - **args** (GetObjectAclArgs) - Required - Arguments containing bucket and object name. ### Response #### Success Response (200) - **AccessControlPolicy** - Access control policy. ### Response Example ```java AccessControlPolicy policy = minioClient.getObjectAcl( GetObjectAclArgs.builder().bucket("my-bucketname").object("my-objectname").build()); ``` ``` -------------------------------- ### Get Bucket Versioning Source: https://github.com/minio/minio-java/blob/master/docs/API.md Retrieves the versioning configuration for a specified bucket. ```APIDOC ## GET /bucket/{bucketName}/versioning ### Description Gets versioning configuration of a bucket. ### Method GET ### Endpoint /bucket/{bucketName}/versioning ### Parameters #### Path Parameters - **bucketName** (string) - Required - The name of the bucket. #### Query Parameters None ### Request Body None ### Request Example None ### Response #### Success Response (200) - **versioningConfiguration** (VersioningConfiguration) - Versioning configuration of the bucket. #### Response Example ```json { "versioningConfiguration": { "status": "Enabled" } } ``` ``` -------------------------------- ### Initialize MinIO Client Source: https://github.com/minio/minio-java/blob/master/docs/API.md Demonstrates how to initialize the MinIO client for both MinIO and AWS S3 endpoints. ```APIDOC ## Initialize MinIO Client ### Description Initializes the MinIO client using the builder pattern with endpoint and credentials. ### Request Example ```java // MinIO MinioClient minioClient = MinioClient.builder() .endpoint("https://play.min.io") .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG") .build(); // AWS S3 MinioClient minioClient = MinioClient.builder() .endpoint("https://s3.amazonaws.com") .credentials("YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY") .build(); ``` ``` -------------------------------- ### Get Bucket Tags Source: https://github.com/minio/minio-java/blob/master/docs/API.md Retrieves the tags associated with a specified bucket. ```APIDOC ## GET /bucket/{bucketName}/tags ### Description Gets tags of a bucket. ### Method GET ### Endpoint /bucket/{bucketName}/tags ### Parameters #### Path Parameters - **bucketName** (string) - Required - The name of the bucket. #### Query Parameters None ### Request Body None ### Request Example None ### Response #### Success Response (200) - **tags** (Tags) - Tags associated with the bucket. #### Response Example ```json { "tags": { "Key1": "Value1", "Key2": "Value2" } } ``` ``` -------------------------------- ### Initialize MinioAdminClient Source: https://github.com/minio/minio-java/blob/master/_autodocs/06-admin-client.md Returns a builder to construct a MinioAdminClient instance. Use this to set the endpoint and credentials for connecting to the MinIO server. ```java MinioAdminClient adminClient = MinioAdminClient.builder() .endpoint("https://minio.example.com:9000") .credentials("minioadmin", "minioadmin") .build(); ``` -------------------------------- ### Get Bucket Replication Source: https://github.com/minio/minio-java/blob/master/docs/API.md Retrieves the replication configuration for a specified bucket. ```APIDOC ## GET /bucket/{bucketName}/replication ### Description Gets bucket replication configuration of a bucket. ### Method GET ### Endpoint /bucket/{bucketName}/replication ### Parameters #### Path Parameters - **bucketName** (string) - Required - The name of the bucket. #### Query Parameters None ### Request Body None ### Request Example None ### Response #### Success Response (200) - **replicationConfiguration** (ReplicationConfiguration) - Bucket replication configuration. #### Response Example ```json { "replicationConfiguration": { "role": "arn:aws:iam::123456789012:role/minio-replication-role", "rules": [ { "id": "rule1", "status": "Enabled", "destination": { "bucket": "arn:aws:s3:::destination-bucket" } } ] } } ``` ``` -------------------------------- ### Initialize MinIO Client with Builder Source: https://github.com/minio/minio-java/blob/master/docs/API.md Various configurations for creating a MinIO client, including anonymous access, authenticated access, and custom region or HTTP client settings. ```java // 1. Create client to S3 service 'play.min.io' at port 443 with TLS security // for anonymous access. MinioClient minioClient = MinioClient.builder().endpoint("https://play.min.io").build(); // 2. Create client to S3 service 'play.min.io' at port 443 with TLS security // using URL object for anonymous access. MinioClient minioClient = MinioClient.builder().endpoint(new URL("https://play.min.io")).build(); // 3. Create client to S3 service 'play.min.io' at port 9000 with TLS security // using okhttp3.HttpUrl object for anonymous access. MinioClient minioClient = MinioClient.builder().endpoint(HttpUrl.parse("https://play.min.io:9000")).build(); // 4. Create client to S3 service 'play.min.io' at port 443 with TLS security // for authenticated access. MinioClient minioClient = MinioClient.builder() .endpoint("https://play.min.io") .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG") .build(); // 5. Create client to S3 service 'play.min.io' at port 9000 with non-TLS security // for authenticated access. MinioClient minioClient = MinioClient.builder() .endpoint("play.min.io", 9000, false) .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG") .build(); // 6. Create client to S3 service 'play.min.io' at port 9000 with TLS security // for authenticated access. MinioClient minioClient = MinioClient.builder() .endpoint("play.min.io", 9000, true) .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG") .build(); // 7. Create client to S3 service 'play.min.io' at port 443 with TLS security // and region 'us-west-1' for authenticated access. MinioClient minioClient = MinioClient.builder() .endpoint(new URL("https://play.min.io")) .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG") .region("us-west-1") .build(); // 8. Create client to S3 service 'play.min.io' at port 9000 with TLS security, // region 'eu-east-1' and custom HTTP client for authenticated access. MinioClient minioClient = MinioClient.builder() .endpoint("https://play.min.io:9000") .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG") .region("eu-east-1") .httpClient(customHttpClient) .build(); ``` -------------------------------- ### Get Bucket Notification Configuration Source: https://github.com/minio/minio-java/blob/master/docs/API.md Retrieves the notification configuration for a bucket. ```java NotificationConfiguration config = minioClient.getBucketNotification( GetBucketNotificationArgs.builder().bucket("my-bucketname").build()); ``` -------------------------------- ### Initialize MinIO Client Source: https://github.com/minio/minio-java/blob/master/docs/API.md Use the MinioClient builder to configure connectivity to a MinIO or S3-compatible endpoint with credentials. ```java MinioClient minioClient = MinioClient.builder() .endpoint("https://play.min.io") .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG") .build(); ``` ```java MinioClient minioClient = MinioClient.builder() .endpoint("https://s3.amazonaws.com") .credentials("YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY") .build(); ``` -------------------------------- ### Get Bucket Lifecycle Configuration Source: https://github.com/minio/minio-java/blob/master/docs/API.md Retrieves the lifecycle configuration for a bucket. ```java LifecycleConfiguration config = minioClient.getBucketLifecycle( GetBucketLifecycleArgs.builder().bucket("my-bucketname").build()); System.out.println("Lifecycle configuration: " + config); ``` -------------------------------- ### Minio Client Initialization with Environment Variables Source: https://github.com/minio/minio-java/blob/master/_autodocs/08-usage-patterns.md Initialize the Minio client by reading endpoint and credentials from environment variables. This is a common practice for security and flexibility in different environments. ```java MinioClient minioClient = MinioClient.builder() .endpoint(System.getenv("S3_ENDPOINT")) .credentials( System.getenv("AWS_ACCESS_KEY_ID"), System.getenv("AWS_SECRET_ACCESS_KEY")) .build(); ``` -------------------------------- ### Get Bucket CORS Configuration Source: https://github.com/minio/minio-java/blob/master/docs/API.md Retrieves the CORS configuration for a bucket. ```java CORSConfiguration config = minioClient.getBucketCors(GetBucketCorsArgs.builder().bucket("my-bucketname").build()); ``` -------------------------------- ### Fetch and Display Credentials Source: https://github.com/minio/minio-java/blob/master/_autodocs/05-configuration-and-credentials.md Demonstrates how to fetch credentials from a provider and display their details. Useful for debugging or understanding the fetched credentials. ```java import io.minio.credentials.Provider; import io.minio.credentials.Credentials; Provider provider = createProvider(); Credentials creds = provider.fetch(); System.out.println("Access Key: " + creds.accessKey()); System.out.println("Has Session Token: " + (creds.sessionToken() != null)); if (creds.expiration() != null) { System.out.println("Expires at: " + creds.expiration()); } ``` -------------------------------- ### Get Object Lock Configuration Source: https://github.com/minio/minio-java/blob/master/docs/API.md Retrieves the object-lock configuration for a specified bucket. ```APIDOC ## GET /bucket/{bucketName}/object-lock ### Description Gets object-lock configuration in a bucket. ### Method GET ### Endpoint /bucket/{bucketName}/object-lock ### Parameters #### Path Parameters - **bucketName** (string) - Required - The name of the bucket. #### Query Parameters None ### Request Body None ### Request Example None ### Response #### Success Response (200) - **objectLockConfiguration** (ObjectLockConfiguration) - Default retention configuration for the bucket. #### Response Example ```json { "objectLockConfiguration": { "rule": { "defaultRetention": { "mode": "COMPLIANCE", "days": 30 } } } } ``` ``` -------------------------------- ### Run build and tests Source: https://github.com/minio/minio-java/blob/master/CONTRIBUTING.md Execute build and functional tests using Gradle. ```bash ./gradlew build ``` ```bash ./gradlew runFunctionalTest ``` -------------------------------- ### Get Bucket Policy Source: https://github.com/minio/minio-java/blob/master/docs/API.md Retrieves the bucket policy configuration for a specified bucket. ```APIDOC ## GET /bucket/{bucketName}/policy ### Description Gets bucket policy configuration of a bucket. ### Method GET ### Endpoint /bucket/{bucketName}/policy ### Parameters #### Path Parameters - **bucketName** (string) - Required - The name of the bucket. #### Query Parameters None ### Request Body None ### Request Example None ### Response #### Success Response (200) - **policy** (string) - Bucket policy configuration as JSON string. #### Response Example ```json { "policy": "{\"Version\": \"2012-10-17\", \"Statement\": [{\"Effect\": \"Allow\", \"Principal\": {\"AWS\": [\"arn:aws:iam::123456789012:root\"]},\"Action\": [\"s3:GetObject\"],\"Resource\": [\"arn:aws:s3:::my-bucketname/*\"]}]}" } ``` ``` -------------------------------- ### MinioAdminClient Initialization Source: https://github.com/minio/minio-java/blob/master/_autodocs/06-admin-client.md Provides a builder to construct a MinioAdminClient instance for administrative operations. ```APIDOC ## MinioAdminClient Initialization ### builder() ```java public static Builder builder() ``` Returns a builder to construct a `MinioAdminClient` instance. **Example**: ```java MinioAdminClient adminClient = MinioAdminClient.builder() .endpoint("https://minio.example.com:9000") .credentials("minioadmin", "minioadmin") .build(); ``` ``` -------------------------------- ### Get Bucket Notification Configuration Source: https://github.com/minio/minio-java/blob/master/docs/API.md Retrieves the notification configuration for a specified bucket. ```APIDOC ## GET /minio/bucket/notification ### Description Gets notification configuration of a bucket. ### Method GET ### Endpoint `/minio/bucket/notification` ### Parameters #### Path Parameters - **bucket** (string) - Required - The name of the bucket. ### Request Body This endpoint does not require a request body. ### Response #### Success Response (200) - **NotificationConfiguration** (object) - The notification configuration of the bucket. #### Error Response (404, 500) - **Error** (string) - Description of the error. ### Example ```java NotificationConfiguration config = minioClient.getBucketNotification( GetBucketNotificationArgs.builder().bucket("my-bucketname").build()); ``` ``` -------------------------------- ### Build and Verify SDK Source: https://github.com/minio/minio-java/blob/master/MAINTAINERS.md Execute the `runFunctionalTest` Gradle task to build the SDK and verify its functionality. ```sh $ ./gradlew runFunctionalTest ``` -------------------------------- ### Get Bucket Lifecycle Configuration Source: https://github.com/minio/minio-java/blob/master/docs/API.md Retrieves the lifecycle configuration for a specified bucket. ```APIDOC ## GET /minio/bucket/lifecycle ### Description Gets lifecycle configuration of a bucket. ### Method GET ### Endpoint `/minio/bucket/lifecycle` ### Parameters #### Path Parameters - **bucket** (string) - Required - The name of the bucket. ### Request Body This endpoint does not require a request body. ### Response #### Success Response (200) - **LifecycleConfiguration** (object) - The lifecycle configuration of the bucket. #### Error Response (404, 500) - **Error** (string) - Description of the error. ### Example ```java LifecycleConfiguration config = minioClient.getBucketLifecycle( GetBucketLifecycleArgs.builder().bucket("my-bucketname").build()); System.out.println("Lifecycle configuration: " + config); ``` ``` -------------------------------- ### MinIO Client Builder Configuration Source: https://github.com/minio/minio-java/blob/master/docs/API.md Demonstrates various ways to configure the MinIO client using the builder pattern, including setting the endpoint, credentials, region, and HTTP client. ```APIDOC ## MinIO Client Builder Configuration This section outlines how to build a MinIO client instance using the `MinioClient.builder()` method. Various configuration options are available to customize the client's behavior. ### Endpoint Configuration The `endpoint()` method accepts the MinIO service endpoint. It can be provided as a String, a `java.net.URL` object, or an `okhttp3.HttpUrl` object. Optionally, a port number and a boolean flag for enabling TLS security can be provided. **Endpoint String Formats:** - `https://s3.amazonaws.com` - `https://play.min.io` - `https://play.min.io:9000` - `localhost` - `play.min.io` **Builder Methods:** - `endpoint(String endpoint)` - `endpoint(String endpoint, int port, boolean secure)` - `endpoint(URL url)` - `endpoint(HttpUrl url)` ### Credentials Configuration The `credentials()` method is used to provide the access key and secret key for authenticated access to the S3 service. **Builder Method:** - `credentials(String accessKey, String secretKey)` ### Region Configuration The `region()` method specifies the region of the S3 service. If not provided, the region is probed per bucket. **Builder Method:** - `region(String region)` ### HTTP Client Configuration The `httpClient()` method allows for overriding the default HTTP client with a custom one. **Builder Method:** - `httpClient(OkHttpClient httpClient)` ### Examples **1. Anonymous Access (TLS Enabled):** ```java MinioClient minioClient = MinioClient.builder().endpoint("https://play.min.io").build(); ``` **2. Anonymous Access (TLS Enabled with URL Object):** ```java MinioClient minioClient = MinioClient.builder().endpoint(new URL("https://play.min.io")).build(); ``` **3. Anonymous Access (TLS Enabled with HttpUrl Object):** ```java MinioClient minioClient = MinioClient.builder().endpoint(HttpUrl.parse("https://play.min.io:9000")).build(); ``` **4. Authenticated Access (TLS Enabled):** ```java MinioClient minioClient = MinioClient.builder() .endpoint("https://play.min.io") .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG") .build(); ``` **5. Authenticated Access (Non-TLS):** ```java MinioClient minioClient = MinioClient.builder() .endpoint("play.min.io", 9000, false) .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG") .build(); ``` **6. Authenticated Access (TLS Enabled with Port):** ```java MinioClient minioClient = MinioClient.builder() .endpoint("play.min.io", 9000, true) .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG") .build(); ``` **7. Authenticated Access (TLS Enabled with Region):** ```java MinioClient minioClient = MinioClient.builder() .endpoint(new URL("https://play.min.io")) .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG") .region("us-west-1") .build(); ``` **8. Authenticated Access (TLS Enabled, Region, Custom HTTP Client):** ```java MinioClient minioClient = MinioClient.builder() .endpoint("https://play.min.io:9000") .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG") .region("eu-east-1") .httpClient(customHttpClient) .build(); ``` ``` -------------------------------- ### makeBucket Source: https://github.com/minio/minio-java/blob/master/_autodocs/01-minio-client.md Creates a new bucket in the MinIO or S3 storage. ```APIDOC ## makeBucket ### Description Creates a new bucket. ### Method `public void makeBucket(MakeBucketArgs args) throws MinioException` ### Parameters - **args** (`MakeBucketArgs`): Builder args with bucket name and optionally region. ### Throws `MinioException` - On SDK errors. ### Example ```java // Create bucket without specifying region minioClient.makeBucket( MakeBucketArgs.builder().bucket("my-bucket").build()); // Create bucket with specified region minioClient.makeBucket( MakeBucketArgs.builder() .bucket("my-bucket") .region("us-east-1") .build()); ``` ``` -------------------------------- ### Get Bucket CORS Configuration Source: https://github.com/minio/minio-java/blob/master/docs/API.md Retrieves the CORS configuration for a specified bucket. ```APIDOC ## GET /minio/bucket/cors ### Description Gets CORS configuration of a bucket. ### Method GET ### Endpoint `/minio/bucket/cors` ### Parameters #### Path Parameters - **bucket** (string) - Required - The name of the bucket. ### Request Body This endpoint does not require a request body. ### Response #### Success Response (200) - **CORSConfiguration** (object) - The CORS configuration of the bucket. #### Error Response (404, 500) - **Error** (string) - Description of the error. ### Example ```java CORSConfiguration config = minioClient.getBucketCors(GetBucketCorsArgs.builder().bucket("my-bucketname").build()); ``` ``` -------------------------------- ### Initialize MinioClient with Builder Source: https://github.com/minio/minio-java/blob/master/_autodocs/01-minio-client.md Construct a MinioClient instance using the builder pattern. Specify the endpoint and credentials. ```java MinioClient minioClient = MinioClient.builder() .endpoint("https://play.min.io") .credentials("accessKey", "secretKey") .build(); ``` -------------------------------- ### Get Bucket Encryption Configuration Source: https://github.com/minio/minio-java/blob/master/docs/API.md Retrieves the server-side encryption configuration for a bucket. ```java SseConfiguration config = minioClient.getBucketEncryption( GetBucketEncryptionArgs.builder().bucket("my-bucketname").build()); ``` -------------------------------- ### Get Bucket Encryption Configuration Source: https://github.com/minio/minio-java/blob/master/docs/API.md Retrieves the server-side encryption configuration for a specified bucket. ```APIDOC ## GET /minio/bucket/encryption ### Description Gets encryption configuration of a bucket. ### Method GET ### Endpoint `/minio/bucket/encryption` ### Parameters #### Path Parameters - **bucket** (string) - Required - The name of the bucket. ### Request Body This endpoint does not require a request body. ### Response #### Success Response (200) - **SseConfiguration** (object) - The server-side encryption configuration of the bucket. #### Error Response (404, 500) - **Error** (string) - Description of the error. ### Example ```java SseConfiguration config = minioClient.getBucketEncryption( GetBucketEncryptionArgs.builder().bucket("my-bucketname").build()); ``` ``` -------------------------------- ### Get Object Retention Policy Source: https://github.com/minio/minio-java/blob/master/_autodocs/07-advanced-operations.md Retrieve the current retention policy applied to a specific object. ```java // Get retention Retention current = minioClient.getObjectRetention( GetObjectRetentionArgs.builder() .bucket("my-bucket") .object("sensitive-data") .build()); ``` -------------------------------- ### Create Bucket with Default Region Source: https://github.com/minio/minio-java/blob/master/docs/API.md Use this to create a bucket with the default region configuration. ```java minioClient.makeBucket( MakeBucketArgs.builder() .bucket("my-bucketname") .build()); ``` -------------------------------- ### Configure Minio Client with Environment Variables and Secrets Management Source: https://github.com/minio/minio-java/blob/master/_autodocs/05-configuration-and-credentials.md Use this for production MinIO servers, reading access and secret keys from a secure secrets management system. ```java // Read from secure secret management system String accessKey = getSecureSecret("MINIO_ACCESS_KEY"); String secretKey = getSecureSecret("MINIO_SECRET_KEY"); MinioClient client = MinioClient.builder() .endpoint("https://minio.example.com") .credentials(accessKey, secretKey) .build(); ``` -------------------------------- ### Get Service Account Info Source: https://github.com/minio/minio-java/blob/master/_autodocs/06-admin-client.md Retrieves details for a specific service account using its access key. ```java GetServiceAccountInfoResponse info = adminClient.getServiceAccountInfo("serviceAccessKey"); System.out.println("Parent User: " + info.parentUser()); System.out.println("Status: " + info.status()); ``` -------------------------------- ### Get Bucket Tags - Java Source: https://github.com/minio/minio-java/blob/master/docs/API.md Retrieves the tags associated with a bucket. The bucket name must be specified. ```java Tags tags = minioClient.getBucketTags(GetBucketTagsArgs.builder().bucket("my-bucketname").build()); ``` -------------------------------- ### Configure Minio Client with Environment Credential Provider Source: https://github.com/minio/minio-java/blob/master/_autodocs/05-configuration-and-credentials.md Use the EnvironmentProvider to dynamically fetch credentials from environment variables (MINIO_ROOT_USER and MINIO_ROOT_PASSWORD). This allows for flexible credential management without hardcoding keys. ```java import io.minio.credentials.EnvironmentProvider; Provider provider = new EnvironmentProvider(); MinioClient client = MinioClient.builder() .endpoint("https://s3.amazonaws.com") .credentialsProvider(provider) .build(); ``` -------------------------------- ### Manage Bucket Tags Source: https://github.com/minio/minio-java/blob/master/_autodocs/01-minio-client.md Set, get, or delete metadata tags for a bucket. Used for organizing and identifying buckets. ```java public void setBucketTags(SetBucketTagsArgs args) throws MinioException public Tags getBucketTags(GetBucketTagsArgs args) throws MinioException public void deleteBucketTags(DeleteBucketTagsArgs args) throws MinioException ``` -------------------------------- ### Simple Object Download to File Source: https://github.com/minio/minio-java/blob/master/_autodocs/08-usage-patterns.md Download an object from a Minio bucket and save it to a local file path. This is the most direct way to retrieve an object as a file. ```java minioClient.downloadObject( DownloadObjectArgs.builder() .bucket("my-bucket") .object("my-object") .filename("/path/to/output") .build()); ``` -------------------------------- ### Configure SSL/TLS Verification in Java Source: https://github.com/minio/minio-java/blob/master/_autodocs/05-configuration-and-credentials.md Demonstrates how to correctly configure SSL/TLS verification for OkHttpClient. Avoid disabling verification; instead, use certificate pinning for self-signed certificates. ```java // ❌ WRONG: Disable SSL verification OkHttpClient httpClient = new OkHttpClient.Builder() .hostnameVerifier((hostname, session) -> true) .build(); ``` ```java // ✅ CORRECT: Keep SSL verification enabled // Default OkHttpClient has SSL verification enabled ``` ```java // ✅ CORRECT: For self-signed certificates, use certificate pinning CertificatePinner certificatePinner = new CertificatePinner.Builder() .add("storage.example.com", "sha256/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=") .build(); OkHttpClient httpClient = new OkHttpClient.Builder() .certificatePinner(certificatePinner) .build(); ``` -------------------------------- ### Get Bucket Quota Source: https://github.com/minio/minio-java/blob/master/_autodocs/06-admin-client.md Retrieves the current size quota for a bucket in bytes. Returns 0 if no quota is set. ```java long quotaBytes = adminClient.getBucketQuota("my-bucket"); long quotaGiB = quotaBytes / (1024L * 1024L * 1024L); System.out.println("Quota: " + quotaGiB + " GiB"); ``` -------------------------------- ### Configure Minio Client with Environment Variables Source: https://github.com/minio/minio-java/blob/master/_autodocs/05-configuration-and-credentials.md Use this configuration for development environments where environment variables are set for MinIO credentials. ```java MinioClient client = MinioClient.builder() .endpoint("https://play.min.io") .credentialsProvider(new ChainedProvider( new EnvironmentProvider(), new MinioClientConfigProvider())) .build(); ``` -------------------------------- ### Get Bucket Policy - Java Source: https://github.com/minio/minio-java/blob/master/docs/API.md Retrieves the bucket policy configuration for a specified bucket. Requires the bucket name. ```java String config = minioClient.getBucketPolicy(GetBucketPolicyArgs.builder().bucket("my-bucketname").build()); ``` -------------------------------- ### List Buckets in Minio Source: https://github.com/minio/minio-java/blob/master/docs/API.md Lists all buckets in your Minio storage. Requires ListBucketsArgs to be built. ```java List bucketList = minioClient.listBuckets(ListBuckets.builder().extraHeaders(headers).build()); for (Bucket bucket : bucketList) { System.out.println(bucket.creationDate() + ", " + bucket.name()); } ``` -------------------------------- ### Upload Object from Stream Source: https://github.com/minio/minio-java/blob/master/_autodocs/02-args-and-responses.md Example of uploading an object from an InputStream with specified size, content type, and user metadata. ```java minioClient.putObject( PutObjectArgs.builder() .bucket("my-bucket") .object("documents/file.txt") .stream(inputStream, fileSize, 5242880) // 5MB parts .contentType("text/plain") .userMetadata(new HashMap() { put("author", "john"); }) .build()); ``` -------------------------------- ### Handling ErrorResponseException Source: https://github.com/minio/minio-java/blob/master/_autodocs/04-errors.md Example of catching an ErrorResponseException, which indicates a server-side error. The errorResponse() method provides details about the error. ```java try { minioClient.getObject( GetObjectArgs.builder() .bucket("non-existent-bucket") .object("file.txt") .build()); } catch (ErrorResponseException e) { // Server returned an error // e.errorResponse() contains error details } ``` -------------------------------- ### Create a feature branch Source: https://github.com/minio/minio-java/blob/master/CONTRIBUTING.md Initialize a new feature branch for development. ```bash git checkout -b my-new-feature ``` -------------------------------- ### Minio Client Initialization with Custom HTTP Configuration Source: https://github.com/minio/minio-java/blob/master/_autodocs/08-usage-patterns.md Configure custom HTTP client settings, such as connection and read timeouts, for the Minio client. The `httpClient` parameter can be set to `false` to prevent Minio from closing the client on its own. ```java import okhttp3.OkHttpClient; import java.util.concurrent.TimeUnit; OkHttpClient httpClient = new OkHttpClient.Builder() .connectTimeout(60, TimeUnit.SECONDS) .readTimeout(60, TimeUnit.SECONDS) .writeTimeout(60, TimeUnit.SECONDS) .build(); MinioClient minioClient = MinioClient.builder() .endpoint("https://s3.example.com") .credentials(key, secret) .httpClient(httpClient, false) // false = don't close on client close .build(); ``` -------------------------------- ### Get Group Information Source: https://github.com/minio/minio-java/blob/master/_autodocs/06-admin-client.md Retrieves details about a specific group, including its members and status. Use the group name as the parameter. ```java GetGroupInfoResponse groupInfo = adminClient.getGroupInfo("developers"); System.out.println("Members: " + groupInfo.members()); System.out.println("Status: " + groupInfo.status()); ``` -------------------------------- ### makeBucket Source: https://github.com/minio/minio-java/blob/master/docs/API.md Creates a new bucket with optional region and object lock settings. ```APIDOC ## makeBucket(MakeBucketArgs args) ### Description Creates a bucket with given region and object lock feature enabled. ### Parameters - **args** (MakeBucketArgs) - Required - Arguments to create bucket ### Request Example ```java minioClient.makeBucket( MakeBucketArgs.builder() .bucket("my-bucketname") .region("us-west-1") .objectLock(true) .build()); ``` ```