Java Client API Reference Slack

Create MinIO Client.

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();
Bucket operations Object operations
bucketExists composeObject
deleteBucketEncryption copyObject
deleteBucketLifeCycle deleteObjectTags
deleteBucketNotification disableObjectLegalHold
deleteBucketPolicy downloadObject
deleteBucketTags enableObjectLegalHold
deleteDefaultRetention getObject
disableVersioning getObjectRetention
enableVersioning getObjectTags
getBucketEncryption getObjectUrl
getBucketLifeCycle getPresignedObjectUrl
getBucketNotification isObjectLegalHoldEnabled
getBucketPolicy listObjects
getBucketTags presignedPostPolicy
getDefaultRetention putObject
isVersioningEnabled removeObject
listBuckets removeObjects
listenBucketNotification selectObjectContent
listIncompleteUploads setObjectRetention
makeBucket setObjectTags
removeBucket statObject
removeIncompleteUpload uploadObject
setBucketEncryption
setBucketLifeCycle
setBucketNotification
setBucketPolicy
setBucketTags
setDefaultRetention

1. MinIO Client Builder

MinIO Client Builder is used to create MinIO client. Builder has below methods to accept arguments.
| Method | Description |
|-----------------|--------------------------------------------------------------------------------------------------------------------------------------------|
| endpoint() | Accepts endpoint as a String, URL or okhttp3.HttpUrl object and optionally accepts port number and flag to enable secure (TLS) connection. |
| | Endpoint as a string can be formatted like below: |
| | https://s3.amazonaws.com |
| | https://play.min.io |
| | https://play.min.io:9000 |
| | localhost |
| | play.min.io |
| credentials() | Accepts access key (aka user ID) and secret key (aka password) of an account in S3 service. |
| region() | Accepts region name of S3 service. If specified, all operations use this region otherwise region is probed per bucket. |
| httpClient() | Custom HTTP client to override default. |

Examples

MinIO

// 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();

AWS S3

// 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();

// 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();

// 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();

// 4. Create client to S3 service 's3.amazonaws.com' at port 80 with TLS security
// for authenticated access.
MinioClient s3Client =
    MinioClient.builder()
        .endpoint("s3.amazonaws.com")
        .credentials("YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY")
        .build();

// 5. Create client to S3 service 's3.amazonaws.com' at port 443 with non-TLS security
// for authenticated access.
MinioClient s3Client =
    MinioClient.builder()
        .endpoint("s3.amazonaws.com", 433, false)
        .credentials("YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY")
        .build();

// 6. Create client to S3 service 's3.amazonaws.com' at port 80 with non-TLS security
// for authenticated access.
MinioClient s3Client =
    MinioClient.builder()
        .endpoint("s3.amazonaws.com", 80, false)
        .credentials("YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY")
        .build();

// 7. Create client to S3 service 's3.amazonaws.com' at port 80 with TLS security
// for authenticated access.
MinioClient s3Client =
    MinioClient.builder()
        .endpoint("s3.amazonaws.com", 80, true)
        .credentials("YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY")
        .build();

// 8. Create client to S3 service 's3.amazonaws.com' at port 80 with non-TLS security
// and region 'us-west-1' for authenticated access.
MinioClient s3Client =
    MinioClient.builder()
        .endpoint("s3.amazonaws.com", 80, false)
        .credentials("YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY")
        .region("us-west-1")
        .build();

// 9. Create client to S3 service 's3.amazonaws.com' at port 443 with TLS security
// and region 'eu-west-2' for authenticated access.
MinioClient s3Client =
    MinioClient.builder()
        .endpoint("s3.amazonaws.com", 443, true)
        .credentials("YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY").
        .region("eu-west-2")
        .build();

// 10. Create client to S3 service 's3.amazonaws.com' at port 443 with TLS security,
// region 'eu-central-1' and custom HTTP client for authenticated access.
MinioClient s3Client =
    MinioClient.builder()
        .endpoint("s3.amazonaws.com", 443, true)
        .credentials("YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY")
        .region("eu-central-1")
        .httpClient(customHttpClient)
        .build();

Common Exceptions

All APIs throw below exceptions in addition to specific to API.

Exception Cause
ErrorResponseException Thrown to indicate S3 service returned an error response.
IllegalArgumentException Throws to indicate invalid argument passed.
InsufficientDataException Thrown to indicate not enough data available in InputStream.
InternalException Thrown to indicate internal library error.
InvalidBucketNameException Thrown to indicate invalid bucket name passed.
InvalidKeyException Thrown to indicate missing of HMAC SHA-256 library.
InvalidResponseException Thrown to indicate S3 service returned invalid or no error response.
IOException Thrown to indicate I/O error on S3 operation.
NoSuchAlgorithmException Thrown to indicate missing of MD5 or SHA-256 digest library.
XmlParserException Thrown to indicate XML parsing error.

2. Bucket operations

bucketExists(BucketExistsArgs args)

public boolean bucketExists(BucketExistsArgs args) [Javadoc]

Checks if a bucket exists.

Parameters
| Parameter | Type | Description |
|:---------------|:---------------------|:---------------|
| bucketName | BucketExistsArgs | Arguments. |

Returns
boolean - True if the bucket exists.

Example

// Check whether 'my-bucketname' exists or not.
boolean found = 
  minioClient.bucketExists(BucketExistsArgs.builder().bucket("my-bucketname").build());
if (found) {
  System.out.println("my-bucketname exists");
} else {
  System.out.println("my-bucketname does not exist");
}

deleteBucketEncryption(DeleteBucketEncryptionArgs args)

private void deleteBucketEncryption(DeleteBucketEncryptionArgs args) [Javadoc]

Deletes encryption configuration of a bucket.

Parameters
| Parameter | Type | Description |
|:----------|:-------------------------------|:------------|
| args | DeleteBucketEncryptionArgs | Arguments. |

Example

minioClient.deleteBucketEncryption(
    DeleteBucketEncryptionArgs.builder().bucket("my-bucketname").build());

deleteBucketLifeCycle(DeleteBucketLifeCycleArgs args)

private void deleteBucketLifeCycle(DeleteBucketLifeCycleArgs args) [Javadoc]

Deletes life-cycle configuration of a bucket.

Parameters
| Parameter | Type | Description |
|:----------|:------------------------------|:------------|
| args | DeleteBucketLifeCycleArgs | Arguments. |

Example

minioClient.deleteBucketLifeCycle(
    DeleteBucketLifeCycleArgs.builder().bucket("my-bucketname").build());

deleteBucketTags(DeleteBucketTagsArgs args)

private void deleteBucketTags(DeleteBucketTagsArgs args) [Javadoc]

Deletes tags of a bucket.

Parameters
| Parameter | Type | Description |
|:----------|:-------------------------|:------------|
| args | DeleteBucketTagsArgs | Arguments. |

Example

minioClient.deleteBucketTags(DeleteBucketTagsArgs.builder().bucket("my-bucketname").build());

deleteBucketPolicy(DeleteBucketPolicyArgs args)

private void deleteBucketPolicy(DeleteBucketPolicyArgs args) [Javadoc]

Deletes bucket policy configuration of a bucket.

Parameters
| Parameter | Type | Description |
|:----------|:---------------------------|:------------|
| args | DeleteBucketPolicyArgs | Argumnets. |

Example

minioClient.deleteBucketPolicy(DeleteBucketPolicyArgs.builder().bucket("my-bucketname").build());

deleteBucketNotification(DeleteBucketNotificationArgs args)

public void deleteBucketNotification(DeleteBucketNotificationArgs args) [Javadoc]

Deletes notification configuration of a bucket.

Parameters
| Parameter | Type | Description |
|:----------|:---------------------------------|:------------|
| args | DeleteBucketNotificationArgs | Arguments. |

Example

minioClient.deleteBucketNotification(
    DeleteBucketNotificationArgs.builder().bucket("my-bucketname").build());

deleteDefaultRetention(DeleteDefaultRetentionArgs args)

public void deleteDefaultRetention(DeleteDefaultRetentionArgs args) [Javadoc]

Deletes default object retention in a bucket.

Parameters
| Parameter | Type | Description |
|:----------|:-------------------------------|:------------|
| args | DeleteDefaultRetentionArgs | Arguments. |

Example

minioClient.deleteDefaultRetention(
    DeleteDefaultRetentionArgs.builder().bucket("my-bucketname").build());

disableVersioning(DisableVersioningArgs args)

public void disableVersioning(DisableVersioningArgs args) [Javadoc]

Disables object versioning feature in a bucket.

Parameters

Parameter Type Description
args DisableVersioningArgs Arguments.

Example

minioClient.disableVersioning(DisableVersioningArgs.builder().bucket("my-bucket").build());

enableVersioning(EnableVersioningArgs args)

public void enableVersioning(EnableVersioningArgs args) [Javadoc]

Enables object versioning feature in a bucket.

Parameters

Parameter Type Description
args EnableVersioningArgs Arguments.

Example

minioClient.enableVersioning(EnableVersioningArgs.builder().bucket("my-bucket").build());

isVersioningEnabled(IsVersioningEnabledArgs args)

public boolean isVersioningEnabled(IsVersioningEnabledArgs args) [Javadoc]

Get bucket version status.

Parameters

Parameter Type Description
args IsVersioningEnabledArgs Arguments.
Returns
boolean - True if bucket versioning is enabled.

Example

boolean isVersioningEnabled =
  minioClient.isVersioningEnabled(
      IsVersioningEnabledArgs.builder().bucket("my-bucketname").build());
if (isVersioningEnabled) {
  System.out.println("Bucket versioning is enabled");
} else {
  System.out.println("Bucket versioning is disabled");
}

getBucketEncryption(GetBucketEncryptionArgs args)

public SseConfiguration getBucketEncryption(GetBucketEncryptionArgs args) [Javadoc]

Gets encryption configuration of a bucket.

Parameters
| Parameter | Type | Description |
|:----------|:----------------------------|:------------|
| args | GetBucketEncryptionArgs | Arguments. |

Returns
SseConfiguration - Server-side encryption configuration.

Example

SseConfiguration config =
    minioClient.getBucketEncryption(
        GetBucketEncryptionArgs.builder().bucket("my-bucketname").build());

getBucketLifeCycle(GetBucketLifeCycleArgs args)

public String getBucketLifeCycle(GetBucketLifeCycleArgs args) [Javadoc]

Gets life-cycle configuration of a bucket.

Parameters
| Parameter | Type | Description |
|:----------|:---------------------------|:------------|
| args | GetBucketLifeCycleArgs | Arguments. |

Returns
String - Life-cycle configuration as XML string.

Example

String lifecycle =
    minioClient.getBucketLifecycle(
        GetBucketLifeCycleArgs.builder().bucket("my-bucketname").build());
System.out.println("Life cycle settings: " + lifecycle);

getBucketNotification(GetBucketNotificationArgs args)

public NotificationConfiguration getBucketNotification(GetBucketNotificationArgs args) [Javadoc]

Gets notification configuration of a bucket.

Parameters
| Parameter | Type | Description |
|:----------|:------------------------------|:------------|
| args | GetBucketNotificationArgs | Arguments. |

Returns
NotificationConfiguration - Notification configuration.

Example

NotificationConfiguration config =
    minioClient.getBucketNotification(
        GetBucketNotificationArgs.builder().bucket("my-bucketname").build());

getBucketPolicy(GetBucketPolicyArgs args)

public String getBucketPolicy(GetBucketPolicyArgs args) [Javadoc]

Gets bucket policy configuration of a bucket.

Parameters
| Parameter | Type | Description |
|:----------|:------------------------|:------------|
| args | GetBucketPolicyArgs | Arguments. |

Returns
String - Bucket policy configuration as JSON string.

Example

String config =
    minioClient.getBucketPolicy(GetBucketPolicyArgs.builder().bucket("my-bucketname").build());

getBucketTags(GetBucketTagsArgs args)

public Tags getBucketTags(GetBucketTagsArgs args) [Javadoc]

Gets tags of a bucket.

Parameters
| Parameter | Type | Description |
|:----------|:----------------------|:------------|
| args | GetBucketTagsArgs | Arguments. |

Returns
Tags - tags.

Example

Tags tags = minioClient.getBucketTags(GetBucketTagsArgs.builder().bucket("my-bucketname").build());

getDefaultRetention(GetDefaultRetentionArgs args)

public ObjectLockConfiguration getDefaultRetention(GetDefaultRetentionArgs args) [Javadoc]

Gets default object retention in a bucket.

Parameters

Parameter Type Description
args GetDefaultRetentionArgs Arguments.
Returns
ObjectLockConfiguration - Default retention configuration.

Example

ObjectLockConfiguration config =
    minioClient.getDefaultRetention(
        GetDefaultRetentionArgs.builder().bucket("my-bucketname").build());
System.out.println("Mode: " + config.mode());
System.out.println("Duration: " + config.duration().duration() + " " + config.duration().unit());

listBuckets()

public List<Bucket> listBuckets() [Javadoc]

Lists bucket information of all buckets.

Returns
List<Bucket> - List of bucket information.

Example

List<Bucket> bucketList = minioClient.listBuckets();
for (Bucket bucket : bucketList) {
  System.out.println(bucket.creationDate() + ", " + bucket.name());
}

listenBucketNotification(ListenBucketNotificationArgs args)

public CloseableIterator<Result<NotificationRecords>> listenBucketNotification(ListenBucketNotificationArgs args) [Javadoc]

Listens events of object prefix and suffix of a bucket. The returned closable iterator is lazily evaluated hence its required to iterate to get new records and must be used with try-with-resource to release underneath network resources.

Parameters
| Parameter | Type | Description |
|:----------|:---------------------------------|:------------|
| args | ListenBucketNotificationArgs | Arguments. |

Returns
CloseableIterator<Result<NotificationRecords>> - Lazy closable iterator contains event records.

Example

String[] events = {"s3:ObjectCreated:*", "s3:ObjectAccessed:*"};
try (CloseableIterator<Result<NotificationRecords>> ci =
    minioClient.listenBucketNotification(
        ListenBucketNotificationArgs.builder()
            .bucket("bucketName")
            .prefix("")
            .suffix("")
            .events(events)
            .build())) {
  while (ci.hasNext()) {
    NotificationRecords records = ci.next().get();
    for (Event event : records.events()) {
      System.out.println("Event " + event.eventType() + " occurred at " + event.eventTime()
          + " for " + event.bucketName() + "/" + event.objectName());
    }
  }
}

listIncompleteUploads(ListIncompleteUploadsArgs args)

public Iterable<Result<Upload>> listIncompleteUploads(ListIncompleteUploadsArgs args) [Javadoc]

Lists incomplete object upload information of a bucket.

Parameters

Parameter Type Description
args ListIncompleteUploadsArgs Arguments.
Returns
Iterable<Result<Upload>> - Lazy iterator contains object upload information.

Example

 // Lists incomplete object upload information of a bucket.
Iterable<Result<Upload>> results =
    minioClient.listIncompleteUploads(
        ListIncompleteUploadsArgs.builder().bucket("my-bucketname").build());
for (Result<Upload> result : results) {
  Upload upload = result.get();
  System.out.println(upload.uploadId() + ", " + upload.objectName());
}

// Lists incomplete object upload information of a bucket for prefix.
Iterable<Result<Upload>> results =
    minioClient.listIncompleteUploads(
        ListIncompleteUploadsArgs.builder()
            .bucket("my-bucketname")
            .prefix("my-obj")
            .build());
for (Result<Upload> result : results) {
  Upload upload = result.get();
  System.out.println(upload.uploadId() + ", " + upload.objectName());
}

// Lists incomplete object upload information of a bucket for prefix recursively.
Iterable<Result<Upload>> results =
    minioClient.listIncompleteUploads(
        ListIncompleteUploadsArgs.builder()
            .bucket("my-bucketname")
            .prefix("my-obj")
            .recursive(true)
            .build());
for (Result<Upload> result : results) {
  Upload upload = result.get();
  System.out.println(upload.uploadId() + ", " + upload.objectName());
}

// Lists incomplete object upload information of a bucket for prefix, delimiter.
// uploadIdMarker and maxUpload to 500
Iterable<Result<Upload>> results =
    minioClient.listIncompleteUploads(
        ListIncompleteUploadsArgs.builder()
            .bucket("my-bucketname")
            .prefix("my-obj")
            .delimiter("-")
            .maxUploads(500)
            .uploadIdMarker("Xgw4MJT6ZPAVxpY0SAuGN7q4uWJJM22ZYg1W99trdp4tpO88")
            .build());
for (Result<Upload> result : results) {
  Upload upload = result.get();
  System.out.println(upload.uploadId() + ", " + upload.objectName());

listObjects(ListObjectsArgs args)

public Iterable<Result<Item>> listObjects(ListObjectsArgs args) [Javadoc]

Lists object information of a bucket.

Parameters
| Parameter | Type | Description |
|:-----------------|:--------------------|:--------------------------|
| args | ListObjectsArgs | Arguments to list objects |

Returns
Iterable<Result<Item>> - Lazy iterator contains object information.

Example

// Lists objects information.
Iterable<Result<Item>> results = minioClient.listObjects(
    ListObjectsArgs.builder().bucket("my-bucketname").build());

// Lists objects information recursively.
Iterable<Result<Item>> results = minioClient.listObjects(
    ListObjectsArgs.builder().bucket("my-bucketname").recursive(true).build());

// Lists maximum 100 objects information those names starts with 'E' and after 'ExampleGuide.pdf'.
Iterable<Result<Item>> results = minioClient.listObjects(
    ListObjectsArgs.builder()
        .bucket("my-bucketname")
        .startAfter("ExampleGuide.pdf")
        .prefix("E")
        .maxKeys(100)
        .build());

// Lists maximum 100 objects information with version those names starts with 'E' and after
// 'ExampleGuide.pdf'.
Iterable<Result<Item>> results = minioClient.listObjects(
    ListObjectsArgs.builder()
        .bucket("my-bucketname")
        .startAfter("ExampleGuide.pdf")
        .prefix("E")
        .maxKeys(100)
        .includeVersions(true)
        .build());

makeBucket(MakeBucketArgs args)

public void makeBucket(MakeBucketArgs args) [Javadoc]

Creates a bucket with given region and object lock feature enabled.

Parameters

Parameter Type Description
args MakeBucketArgs Arguments to create bucket

Example

// Create bucket with default region.
minioClient.makeBucket(
    MakeBucketArgs.builder()
        .bucket("my-bucketname")
        .build());

// Create bucket with specific region.
minioClient.makeBucket(
    MakeBucketArgs.builder()
        .bucket("my-bucketname")
        .region("us-west-1")
        .build());

// Create object-lock enabled bucket with specific region.
minioClient.makeBucket(
    MakeBucketArgs.builder()
        .bucket("my-bucketname")
        .region("us-west-1")
        .objectLock(true)
        .build());

removeBucket(RemoveBucketArgs args)

public void removeBucket(RemoveBucketArgs args) [Javadoc]

Removes an empty bucket.

Parameters

Parameter Type Description
args RemoveBucketArgs Arguments.

Example

minioClient.removeBucket(RemoveBucketArgs.builder().bucket(bucketName).build());

removeIncompleteUpload(RemoveIncompleteUploadArgs args)

public void removeIncompleteUpload(String bucketName, String objectName) [Javadoc]

Removes incomplete uploads of an object.

Parameters
| Parameter | Type | Description |
|:-----------------|:-------------------------------|:-----------------------------|
| args | RemoveIncompleteUploadArgs | Arguments. |

Example

minioClient.removeIncompleteUpload(
    RemoveIncompleteUploadArgs.builder()
        .bucket("my-bucketname")
        .object("my-objectname")
        .build());

setBucketEncryption(SetBucketEncryptionArgs args)

public void setBucketEncryption(SetBucketEncryptionArgs args) [Javadoc]

Sets encryption configuration of a bucket.

Parameters
| Parameter | Type | Description |
|:----------|:----------------------------|:------------|
| args | SetBucketEncryptionArgs | Arguments. |

Example

minioClient.setBucketEncryption(
    SetBucketEncryptionArgs.builder().bucket("my-bucketname").config(config).build());

setBucketLifeCycle(SetBucketLifeCycleArgs args)

public void setBucketLifeCycle(SetBucketLifeCycleArgs args) [Javadoc]

Sets life-cycle configuration to a bucket.

Parameters
| Parameter | Type | Description |
|:----------|:---------------------------|:------------|
| args | SetBucketLifeCycleArgs | Arguments. |

Example

// Lets consider variable 'lifeCycleXml' contains below XML String;
// <LifecycleConfiguration>
//   <Rule>
//     <ID>expire-bucket</ID>
//     <Prefix></Prefix>
//     <Status>Enabled</Status>
//     <Expiration>
//       <Days>365</Days>
//     </Expiration>
//   </Rule>
// </LifecycleConfiguration>
//
minioClient.setBucketLifecycle(
    SetBucketLifecycleArgs.builder().bucket("my-bucketname").config(lifeCycleXml).build());

setBucketNotification(SetBucketNotificationArgs args)

public void setBucketNotification(SetBucketNotificationArgs args) [Javadoc]

Sets notification configuration to a bucket.

Parameters

Parameter Type Description
args SetBucketNotificationArgs Arguments.

Example

List<EventType> eventList = new LinkedList<>();
eventList.add(EventType.OBJECT_CREATED_PUT);
eventList.add(EventType.OBJECT_CREATED_COPY);

QueueConfiguration queueConfiguration = new QueueConfiguration();
queueConfiguration.setQueue("arn:minio:sqs::1:webhook");
queueConfiguration.setEvents(eventList);
queueConfiguration.setPrefixRule("images");
queueConfiguration.setSuffixRule("pg");

List<QueueConfiguration> queueConfigurationList = new LinkedList<>();
queueConfigurationList.add(queueConfiguration);

NotificationConfiguration config = new NotificationConfiguration();
config.setQueueConfigurationList(queueConfigurationList);

minioClient.setBucketNotification(
    SetBucketNotificationArgs.builder().bucket("my-bucketname").config(config).build());

setBucketPolicy(SetBucketPolicyArgs args)

public void setBucketPolicy(SetBucketPolicyArgs args) [Javadoc]

Sets bucket policy configuration to a bucket.

Parameters

Parameter Type Description
args SetBucketPolicyArgs Arguments.

Example

// Assume policyJson contains below JSON string;
// {
//     "Statement": [
//         {
//             "Action": [
//                 "s3:GetBucketLocation",
//                 "s3:ListBucket"
//             ],
//             "Effect": "Allow",
//             "Principal": "*",
//             "Resource": "arn:aws:s3:::my-bucketname"
//         },
//         {
//             "Action": "s3:GetObject",
//             "Effect": "Allow",
//             "Principal": "*",
//             "Resource": "arn:aws:s3:::my-bucketname/myobject*"
//         }
//     ],
//     "Version": "2012-10-17"
// }
//
minioClient.setBucketPolicy(
    SetBucketPolicyArgs.builder().bucket("my-bucketname").config(policyJson).build());

setBucketTags(SetBucketTagsArgs args)

public void setBucketTags(SetBucketTagsArgs args) [Javadoc]

Sets tags to a bucket.

Parameters

Parameter Type Description
args SetBucketTagsArgs Arguments.

Example

Map<String, String> map = new HashMap<>();
map.put("Project", "Project One");
map.put("User", "jsmith");
minioClient.setBucketTags(SetBucketTagsArgs.builder().bucket("my-bucketname").tags(map).build());

setDefaultRetention(SetDefaultRetentionArgs args)

public void setDefaultRetention(SetDefaultRetentionArgs args) [Javadoc]

Sets default object retention in a bucket.

Parameters
| Parameter | Type | Description |
|:----------|:----------------------------|:------------|
| args | SetDefaultRetentionArgs | Arguments. |

Example

ObjectLockConfiguration config =
    new ObjectLockConfiguration(RetentionMode.COMPLIANCE, new RetentionDurationDays(100));
minioClient.setDefaultRetention(
    SetDefaultRetentionArgs.builder().bucket("my-bucketname").config(config).build());

3. Object operations

composeObject(ComposeObjectArgs args)

public ObjectWriteResponse composeObject(ComposeObjectArgs args) [Javadoc]

Creates an object by combining data from different source objects using server-side copy.

Parameters
| Param | Type | Description |
|:---------------|:-------------------------|:--------------|
| args | ComposeObjectArgs | Arguments. |

Returns
ObjectWriteResponse - Contains information of created object.

Example

List<ComposeSource> sourceObjectList = new ArrayList<ComposeSource>();
sourceObjectList.add(
  ComposeSource.builder().bucket("my-job-bucket").object("my-objectname-part-one").build());
sourceObjectList.add(
  ComposeSource.builder().bucket("my-job-bucket").object("my-objectname-part-two").build());
sourceObjectList.add(
  ComposeSource.builder().bucket("my-job-bucket").object("my-objectname-part-three").build());

// Create my-bucketname/my-objectname by combining source object list.
minioClient.composeObject(
  ComposeObjectArgs.builder()
      .bucket("my-bucketname")
      .object("my-objectname")
      .sources(sourceObjectList)
      .build());

// Create my-bucketname/my-objectname with user metadata by combining source object
// list.
minioClient.composeObject(
    ComposeObjectArgs.builder()
      .bucket("my-bucketname")
      .object("my-objectname")
      .sources(sourceObjectList)
      .headers(Multimaps.forMap(userMetadata))
      .build());

// Create my-bucketname/my-objectname with user metadata and server-side encryption
// by combining source object list.
minioClient.composeObject(
  ComposeObjectArgs.builder()
      .bucket("my-bucketname")
      .object("my-objectname")
      .sources(sourceObjectList)
      .headers(Multimaps.forMap(userMetadata))
      .ssec(sse)
      .build());

copyObject(CopyObjectArgs args)

public ObjectWriteResponse copyObject(CopyObjectArgs args) [Javadoc]

Creates an object by server-side copying data from another object.

Parameters
| Parameter | Type | Description |
|:----------|:-------------------|:------------|
| args | CopyObjectArgs | Arguments. |

Returns
ObjectWriteResponse - Contains information of created object.

Example

// Create object "my-objectname" in bucket "my-bucketname" by copying from object
// "my-objectname" in bucket "my-source-bucketname".
minioClient.copyObject(
    CopyObjectArgs.builder()
        .bucket("my-bucketname")
        .object("my-objectname")
        .srcBucket("my-source-bucketname")
        .build());

// Create object "my-objectname" in bucket "my-bucketname" by copying from object
// "my-source-objectname" in bucket "my-source-bucketname".
minioClient.copyObject(
    CopyObjectArgs.builder()
        .bucket("my-bucketname")
        .object("my-objectname")
        .srcBucket("my-source-bucketname")
        .srcObject("my-source-objectname")
        .build());

// Create object "my-objectname" in bucket "my-bucketname" with server-side encryption by
// copying from object "my-objectname" in bucket "my-source-bucketname".
minioClient.copyObject(
    CopyObjectArgs.builder()
        .bucket("my-bucketname")
        .object("my-objectname")
        .srcBucket("my-source-bucketname")
        .sse(sse)
        .build());

// Create object "my-objectname" in bucket "my-bucketname" by copying from SSE-C encrypted
// object "my-source-objectname" in bucket "my-source-bucketname".
minioClient.copyObject(
    CopyObjectArgs.builder()
        .bucket("my-bucketname")
        .object("my-objectname")
        .srcBucket("my-source-bucketname")
        .srcObject("my-source-objectname")
        .srcSsec(ssec)
        .build());

// Create object "my-objectname" in bucket "my-bucketname" with custom headers by copying from
// object "my-objectname" in bucket "my-source-bucketname" using conditions.
minioClient.copyObject(
    CopyObjectArgs.builder()
        .bucket("my-bucketname")
        .object("my-objectname")
        .srcBucket("my-source-bucketname")
        .headers(headers)
        .srcMatchETag(etag)
        .build());

deleteObjectTags(DeleteObjectTagsArgs args)

private void deleteObjectTags(DeleteObjectTagsArgs args) [Javadoc]

Deletes tags of an object.

Parameters
| Parameter | Type | Description |
|:----------|:-------------------------|:------------|
| args | DeleteObjectTagsArgs | Arguments. |

Example

minioClient.deleteObjectTags(
    DeleteObjectArgs.builder().bucket("my-bucketname").object("my-objectname").build());

disableObjectLegalHold(DisableObjectLegalHoldArgs args)

public void disableObjectLegalHold(DisableObjectLegalHoldArgs args) [Javadoc]

Disables legal hold on an object.

Parameters

Parameter Type Description
args DisableObjectLegalHoldArgs Arguments.

Example

// Disables legal hold on an object.
minioClient.disableObjectLegalHold(
    DisableObjectLegalHoldArgs.builder()
        .bucket("my-bucketname")
        .object("my-objectname")
        .build());

enableObjectLegalHold(EnableObjectLegalHoldArgs args)

public void enableObjectLegalHold(EnableObjectLegalHoldArgs args) [Javadoc]

Enables legal hold on an object.

Parameters

Parameter Type Description
args EnableObjectLegalHoldArgs Argumments.

Example


 // Disables legal hold on an object.
minioClient.enableObjectLegalHold(
    EnableObjectLegalHoldArgs.builder()
        .bucket("my-bucketname")
        .object("my-objectname")
        .build());

getObject(GetObjectArgs args)

public InputStream getObject(GetObjectArgs args) [Javadoc]

Gets data of an object. Returned InputStream must be closed after use to release network resources.

Parameters
| Parameter | Type | Description |
|:---------------|:----------------|:---------------------------|
| args | GetObjectArgs | Arguments. |

Returns
InputStream - Contains object data.

Example

// get object given the bucket and object name
try (InputStream stream = minioClient.getObject(
  GetObjectArgs.builder()
  .bucket("my-bucketname")
  .object("my-objectname")
  .build()) {
  // Read data from stream
}

// get object data from offset
try (InputStream stream = minioClient.getObject(
  GetObjectArgs.builder()
  .bucket("my-bucketname")
  .object("my-objectname")
  .offset(1024L)
  .build()) {
  // Read data from stream
}

// get object data from offset to length
try (InputStream stream = minioClient.getObject(
  GetObjectArgs.builder()
  .bucket("my-bucketname")
  .object("my-objectname")
  .offset(1024L)
  .length(4096L)
  .build()) {
  // Read data from stream
}

// get data of an SSE-C encrypted object
try (InputStream stream = minioClient.getObject(
  GetObjectArgs.builder()
  .bucket("my-bucketname")
  .object("my-objectname")
  .ssec(ssec)
  .build()) {
  // Read data from stream
}

// get object data from offset to length of an SSE-C encrypted object
try (InputStream stream = minioClient.getObject(
  GetObjectArgs.builder()
  .bucket("my-bucketname")
  .object("my-objectname")
  .offset(1024L)
  .length(4096L)
  .ssec(ssec)
  .build()) {
  // Read data from stream
}

downloadObject(DownloadObjectArgs args)

public void downloadObject(DownloadObjectArgs args) [Javadoc]

Downloads data of an object to file.

Parameters
| Parameter | Type | Description |
|:-----------------|:---------------------|:-----------------------------|
| args | DownloadObjectArgs | Arguments. |

Example

// Download object given the bucket, object name and output file name
minioClient.downloadObject(
  DownloadObjectArgs.builder()
  .bucket("my-bucketname")
  .object("my-objectname")
  .fileName("my-object-file")
  .build());

// Download server-side encrypted object in bucket to given file name
minioClient.downloadObject(
  DownloadObjectArgs.builder()
  .bucket("my-bucketname")
  .object("my-objectname")
  .ssec(ssec)
  .fileName("my-object-file")
  .build());

getObjectRetention(GetObjectRetentionArgs args)

public Retention getObjectRetention(GetObjectRetentionArgs args) [Javadoc]

Gets retention configuration of an object.

Parameters

Parameter Type Description
args GetObjectRetentionArgs Arguments.
Returns
Retention - Object retention configuration.

Example

// Object with version id.
Retention retention =
    minioClient.getObjectRetention(
        GetObjectRetentionArgs.builder()
            .bucket("my-bucketname")
            .object("my-objectname")
            .versionId("object-version-id")
            .build());
System.out.println("mode: " + retention.mode() + "until: " + retention.retainUntilDate());

getObjectTags(GetObjectTagsArgs args)

public Tags getObjectTags(GetObjectTagsArgs args) [Javadoc]

Gets tags of an object.

Parameters
| Parameter | Type | Description |
|:----------|:----------------------|:------------|
| args | GetObjectTagsArgs | Arguments. |

Returns
Tags - tags.

Example

Tags tags = minioClient.getObjectTags(
    GetObjectTagsArgs.builder().bucket("my-bucketname").object("my-objectname").build());

getObjectUrl(String bucketName, String objectName)

public String getObjectUrl(String bucketName, String objectName) [Javadoc]

Gets URL of an object useful when this object has public read access.

Parameters
| Parameter | Type | Description |
|:---------------|:---------|:---------------------------|
| bucketName | String | Name of the bucket. |
| objectName | String | Object name in the bucket. |

Returns
String - URL string.

Example

String url = minioClient.getObjectUrl("my-bucketname", "my-objectname");
System.out.println("my-bucketname/my-objectname can be downloaded by " + url);

getPresignedObjectUrl(GetPresignedObjectUrlArgs args)

public String getPresignedObjectUrl(GetPresignedObjectUrlArgs args) [Javadoc]

Gets presigned URL of an object for HTTP method, expiry time and custom request parameters.

Parameters
| Parameter | Type | Description |
|:------------|:-------------------------------|:-------------|
| args | GetPresignedObjectUrlArgs | Arguments. |

Returns
String - URL string.

Example

// Get presigned URL of an object for HTTP method, expiry time and custom request parameters.
String url =
    minioClient.getPresignedObjectUrl(
        GetPresignedObjectUrlArgs.builder()
            .method(Method.DELETE)
            .bucket("my-bucketname")
            .object("my-objectname")
            .expiry(24 * 60 * 60)
            .build());
System.out.println(url);

// Get presigned URL string to upload 'my-objectname' in 'my-bucketname' 
// with response-content-type as application/json and life time as one day.
Map<String, String> reqParams = new HashMap<String, String>();
reqParams.put("response-content-type", "application/json");

String url =
    minioClient.getPresignedObjectUrl(
        GetPresignedObjectUrlArgs.builder()
            .method(Method.PUT)
            .bucket("my-bucketname")
            .object("my-objectname")
            .expiry(1, TimeUnit.DAYS)
            .extraQueryParams(reqParams)
            .build());
System.out.println(url);

// Get presigned URL string to download 'my-objectname' in 'my-bucketname' and its life time
// is 2 hours.
String url =
    minioClient.getPresignedObjectUrl(
        GetPresignedObjectUrlArgs.builder()
            .method(Method.GET)
            .bucket("my-bucketname")
            .object("my-objectname")
            .expiry(2, TimeUnit.HOURS)
            .build());
System.out.println(url);

isObjectLegalHoldEnabled(IsObjectLegalHoldEnabledArgs args)

public boolean isObjectLegalHoldEnabled(IsObjectLegalHoldEnabledArgs args) [Javadoc]

Returns true if legal hold is enabled on an object.

Parameters

Parameter Type Description
args IsObjectLegalHoldEnabledArgs Arguments.
Returns
boolean - True if legal hold is enabled.

Example

boolean status =
    s3Client.isObjectLegalHoldEnabled(
       IsObjectLegalHoldEnabledArgs.builder()
            .bucket("my-bucketname")
            .object("my-objectname")
            .versionId("object-versionId")
            .build());
if (status) {
  System.out.println("Legal hold is on");
else {
  System.out.println("Legal hold is off");
}

presignedPostPolicy(PostPolicy policy)

public Map<String,String> presignedPostPolicy(PostPolicy policy) [Javadoc]

Gets form-data of PostPolicy of an object to upload its data using POST method.

Parameters
| Parameter | Type | Description |
|:-----------|:---------------|:--------------------------|
| policy | PostPolicy | Post policy of an object. |

Returns
Map - Contains form-data to upload an object using POST method.

Example

PostPolicy policy = new PostPolicy("my-bucketname", "my-objectname", ZonedDateTime.now().plusDays(7));

// 'my-objectname' should be 'image/png' content type
policy.setContentType("image/png");

// set success action status to 201 to receive XML document
policy.setSuccessActionStatus(201);

Map<String,String> formData = minioClient.presignedPostPolicy(policy);

// Print curl command to be executed by anonymous user to upload /tmp/userpic.png.
System.out.print("curl -X POST ");
for (Map.Entry<String,String> entry : formData.entrySet()) {
  System.out.print(" -F " + entry.getKey() + "=" + entry.getValue());
}
System.out.println(" -F file=@/tmp/userpic.png https://play.min.io/my-bucketname");

putObject(PutObjectArgs args)

public ObjectWriteResponse putObject(PutObjectArgs args) [Javadoc]

Uploads given stream as object in bucket.

Parameters
| Parameter | Type | Description |
|:----------|:------------------|:------------|
| args | PutObjectArgs | Arguments. |

Returns
ObjectWriteResponse - Contains information of created object.

Example

// Upload known sized input stream.
minioClient.putObject(
    PutObjectArgs.builder().bucket("my-bucketname").object("my-objectname").stream(
            inputStream, size, -1)
        .contentType("video/mp4")
        .build());

// Upload unknown sized input stream.
minioClient.putObject(
    PutObjectArgs.builder().bucket("my-bucketname").object("my-objectname").stream(
            inputStream, -1, 10485760)
        .contentType("video/mp4")
        .build());

// Create object ends with '/' (also called as folder or directory).
minioClient.putObject(
    PutObjectArgs.builder().bucket("my-bucketname").object("path/to/").stream(
            new ByteArrayInputStream(new byte[] {}), 0, -1)
        .build());

// Upload input stream with headers and user metadata.
Map<String, String> headers = new HashMap<>();
headers.put("X-Amz-Storage-Class", "REDUCED_REDUNDANCY");
Map<String, String> userMetadata = new HashMap<>();
userMetadata.put("My-Project", "Project One");
minioClient.putObject(
    PutObjectArgs.builder().bucket("my-bucketname").object("my-objectname").stream(
            inputStream, size, -1)
        .headers(headers)
        .userMetadata(userMetadata)
        .build());

// Upload input stream with server-side encryption.
minioClient.putObject(
    PutObjectArgs.builder().bucket("my-bucketname").object("my-objectname").stream(
            inputStream, size, -1)
        .sse(sse)
        .build());

uploadObject(UploadObjectArgs args)

public void uploadObject(UploadObjectArgs args) [Javadoc]

Uploads contents from a file as object in bucket.

Parameters
| Parameter | Type | Description |
|:----------|:---------------------|:------------|
| args | UploadObjectArgs | Arguments. |

Example

// Upload an JSON file.
minioClient.uploadObject(
    UploadObjectArgs.builder()
        .bucket("my-bucketname").object("my-objectname").filename("person.json").build());

// Upload a video file.
minioClient.uploadObject(
    UploadObjectArgs.builder()
        .bucket("my-bucketname")
        .object("my-objectname")
        .filename("my-video.avi")
        .contentType("video/mp4")
        .build());

removeObject(RemoveObjectArgs args)

public void removeObject(RemoveObjectArgs args) [Javadoc]

Removes an object.

Parameters
| Parameter | Type | Description |
|:----------|:---------------------|:------------|
| args | RemoveObjectArgs | Arguments. |

Example

// Remove object.
minioClient.removeObject(
    RemoveObjectArgs.builder().bucket("my-bucketname").object("my-objectname").build());

// Remove versioned object.
minioClient.removeObject(
    RemoveObjectArgs.builder()
        .bucket("my-bucketname")
        .object("my-versioned-objectname")
        .versionId("my-versionid")
        .build());

// Remove versioned object bypassing Governance mode.
minioClient.removeObject(
    RemoveObjectArgs.builder()
        .bucket("my-bucketname")
        .object("my-versioned-objectname")
        .versionId("my-versionid")
        .bypassRetentionMode(true)
        .build());

removeObjects(RemoveObjectsArgs args)

public Iterable<Result<DeleteError>> removeObjects(RemoveObjectsArgs args) [Javadoc]

Removes multiple objects lazily. Its required to iterate the returned Iterable to perform removal.

Parameters
| Parameter | Type | Description |
|:----------|:----------------------|:------------|
| args | RemoveObjectsArgs | Arguments. |

Returns
Iterable<Result<DeleteError>> - Lazy iterator contains object removal status.

Example

List<DeleteObject> objects = new LinkedList<>();
objects.add(new DeleteObject("my-objectname1"));
objects.add(new DeleteObject("my-objectname2"));
objects.add(new DeleteObject("my-objectname3"));
Iterable<Result<DeleteError>> results =
    minioClient.removeObjects(
        RemoveObjectsArgs.builder().bucket("my-bucketname").objects(objects).build());
for (Result<DeleteError> result : results) {
  DeleteError error = result.get();
  System.out.println(
      "Error in deleting object " + error.objectName() + "; " + error.message());
}

selectObjectContent(SelectObjectContentArgs args)

public SelectResponseStream selectObjectContent(SelectObjectContentArgs args) [Javadoc]

Selects content of a object by SQL expression.

Parameters

Parameter Type Description
args SelectObjectContentArgs Arguments.
Returns
SelectResponseStream - Contains filtered records and progress.

Example

String sqlExpression = "select * from S3Object";
InputSerialization is = new InputSerialization(null, false, null, null, FileHeaderInfo.USE, null, null, null);
OutputSerialization os = new OutputSerialization(null, null, null, QuoteFields.ASNEEDED, null);
SelectResponseStream stream =
    minioClient.selectObjectContent(
        SelectObjectContentArgs.builder()
            .bucket("my-bucketname")
            .object("my-objectName")
            .sqlExpression(sqlExpression)
            .inputSerialization(is)
            .outputSerialization(os)
            .requestProgress(true)
            .build());

byte[] buf = new byte[512];
int bytesRead = stream.read(buf, 0, buf.length);
System.out.println(new String(buf, 0, bytesRead, StandardCharsets.UTF_8));

Stats stats = stream.stats();
System.out.println("bytes scanned: " + stats.bytesScanned());
System.out.println("bytes processed: " + stats.bytesProcessed());
System.out.println("bytes returned: " + stats.bytesReturned());

stream.close();

setObjectRetention(SetObjectRetentionArgs args)

public void setObjectLockRetention(SetObjectRetentionArgs) [Javadoc]

Sets retention configuration to an object.

Parameters

Parameter Type Description
args SetObjectRetentionArgs Arguments.

Example

Retention retention = new Retention(RetentionMode.COMPLIANCE, ZonedDateTime.now().plusYears(1));
minioClient.setObjectRetention(
    SetObjectRetentionArgs.builder()
        .bucket("my-bucketname")
        .object("my-objectname")
        .config(retention)
        .bypassGovernanceMode(true)
        .build());

setObjectTags(SetObjectTagsArgs args)

public void setObjectTags(SetObjectTagsArgs args) [Javadoc]

Sets tags to an object.

Parameters

Parameter Type Description
args SetObjectTagsArgs Arguments.

Example

Map<String, String> map = new HashMap<>();
map.put("Project", "Project One");
map.put("User", "jsmith");
minioClient.setObjectTags(
    SetObjectTagsArgs.builder().bucket("my-bucketname").object("my-objectname").tags(map).build());

statObject(StatObjectArgs args)

public ObjectStat statObject(StatObjectArgs args) [Javadoc]

Gets object information and metadata of an object.

Parameters
| Parameter | Type | Description |
|:----------|:-------------------|:------------|
| args | StatObjectArgs | Arguments. |

Returns
ObjectStat - Populated object information and metadata.

Example

// Get information of an object.
ObjectStat objectStat =
    minioClient.statObject(
        StatObjectArgs.builder().bucket("my-bucketname").object("my-objectname").build());

// Get information of SSE-C encrypted object.
ObjectStat objectStat =
    minioClient.statObject(
        StatObjectArgs.builder()
            .bucket("my-bucketname")
            .object("my-objectname")
            .ssec(ssec)
            .build());

// Get information of a versioned object.
ObjectStat objectStat =
    minioClient.statObject(
        StatObjectArgs.builder()
            .bucket("my-bucketname")
            .object("my-objectname")
            .versionId("version-id")
            .build());

// Get information of a SSE-C encrypted versioned object.
ObjectStat objectStat =
    minioClient.statObject(
        StatObjectArgs.builder()
            .bucket("my-bucketname")
            .object("my-objectname")
            .versionId("version-id")
            .ssec(ssec)
            .build());

5. Explore Further