Java Client API Reference 
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 | 
|---|---|
1. MinIO Client Builder
MinIO Client Builder is used to create MinIO client. Builder has below methods to accept arguments.
| Method | Description | 
|---|---|
| 
 | 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: | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | Accepts access key (aka user ID) and secret key (aka password) of an account in S3 service. | 
| 
 | Accepts region name of S3 service. If specified, all operations use this region otherwise region is probed per bucket. | 
| 
 | 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. | 
| 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. | 
| ServerException | Thrown to indicate HTTP server error. | 
| 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 | 
|---|---|---|
| 
 | 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 | 
|---|---|---|
| 
 | Arguments. | 
Example
minioClient.deleteBucketEncryption(
    DeleteBucketEncryptionArgs.builder().bucket("my-bucketname").build());
deleteBucketLifecycle(DeleteBucketLifecycleArgs args)
private void deleteBucketLifecycle(DeleteBucketLifecycleArgs args) [Javadoc]
Deletes lifecycle configuration of a bucket.
Parameters
| Parameter | Type | Description | 
|---|---|---|
| 
 | Arguments. | 
Example
minioClient.deleteBucketLifecycle(
    DeleteBucketLifecycleArgs.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 | 
|---|---|---|
| 
 | Arguments. | 
Example
minioClient.deleteBucketPolicy(DeleteBucketPolicyArgs.builder().bucket("my-bucketname").build());
deleteBucketReplication(DeleteBucketReplicationArgs args)
private void deleteBucketReplication(DeleteBucketReplicationArgs args) [Javadoc]
Deletes bucket replication configuration of a bucket.
Parameters
| Parameter | Type | Description | 
|---|---|---|
| 
 | Arguments. | 
Example
minioClient.deleteBucketReplication(
    DeleteBucketReplicationArgs.builder().bucket("my-bucketname").build());
deleteBucketNotification(DeleteBucketNotificationArgs args)
public void deleteBucketNotification(DeleteBucketNotificationArgs args) [Javadoc]
Deletes notification configuration of a bucket.
Parameters
| Parameter | Type | Description | 
|---|---|---|
| 
 | Arguments. | 
Example
minioClient.deleteBucketNotification(
    DeleteBucketNotificationArgs.builder().bucket("my-bucketname").build());
deleteObjectLockConfiguration(DeleteObjectLockConfigurationArgs args)
public void deleteObjectLockConfiguration(DeleteObjectLockConfigurationArgs args) [Javadoc]
Deletes object-lock configuration in a bucket.
Parameters
| Parameter | Type | Description | 
|---|---|---|
| 
 | Arguments. | 
Example
minioClient.deleteObjectLockConfiguration(
    DeleteObjectLockConfigurationArgs.builder().bucket("my-bucketname").build());
getBucketEncryption(GetBucketEncryptionArgs args)
public SseConfiguration getBucketEncryption(GetBucketEncryptionArgs args) [Javadoc]
Gets encryption configuration of a bucket.
Parameters
| Parameter | Type | Description | 
|---|---|---|
| 
 | Arguments. | 
| Returns | 
|---|
| SseConfiguration - Server-side encryption configuration. | 
Example
SseConfiguration config =
    minioClient.getBucketEncryption(
        GetBucketEncryptionArgs.builder().bucket("my-bucketname").build());
getBucketLifecycle(GetBucketLifecycleArgs args)
public LifecycleConfiguration getBucketLifecycle(GetBucketLifecycleArgs args) [Javadoc]
Gets lifecycle configuration of a bucket.
Parameters
| Parameter | Type | Description | 
|---|---|---|
| 
 | Arguments. | 
| Returns | 
|---|
| LifecycleConfiguration - lifecycle configuration. | 
Example
LifecycleConfiguration config =
    minioClient.getBucketLifecycle(
	    GetBucketLifecycleArgs.builder().bucket("my-bucketname").build());
System.out.println("Lifecycle configuration: " + config);
getBucketNotification(GetBucketNotificationArgs args)
public NotificationConfiguration getBucketNotification(GetBucketNotificationArgs args) [Javadoc]
Gets notification configuration of a bucket.
Parameters
| Parameter | Type | Description | 
|---|---|---|
| 
 | 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 | 
|---|---|---|
| 
 | Arguments. | 
| Returns | 
|---|
| String - Bucket policy configuration as JSON string. | 
Example
String config =
    minioClient.getBucketPolicy(GetBucketPolicyArgs.builder().bucket("my-bucketname").build());
getBucketReplication(GetBucketReplicationArgs args)
public ReplicationConfiguration getBucketReplication(GetBucketReplicationArgs args) [Javadoc]
Gets bucket replication configuration of a bucket.
Parameters
| Parameter | Type | Description | 
|---|---|---|
| 
 | Arguments. | 
| Returns | 
|---|
| ReplicationConfiguration - Bucket replication configuration. | 
Example
ReplicationConfiguration config =
    minioClient.getBucketReplication(
	    GetBucketReplicationArgs.builder().bucket("my-bucketname").build());
getBucketVersioning(GetBucketVersioningArgs args)
public VersioningConfiguration getBucketVersioning(GetBucketVersioningArgs args) [Javadoc]
Gets versioning configuration of a bucket.
Parameters
| Parameter | Type | Description | 
|---|---|---|
| 
 | Arguments. | 
| Returns | 
|---|
| VersioningConfiguration - Versioning configuration. | 
Example
VersioningConfiguration config =
    minioClient.getBucketVersioning(
        GetBucketVersioningArgs.builder().bucket("my-bucketname").build());
getObjectLockConfiguration(GetObjectLockConfigurationArgs args)
public ObjectLockConfiguration getObjectLockConfiguration(GetObjectLockConfigurationArgs args) [Javadoc]
Gets object-lock configuration in a bucket.
Parameters
| Parameter | Type | Description | 
|---|---|---|
| 
 | Arguments. | 
| Returns | 
|---|
| ObjectLockConfiguration - Default retention configuration. | 
Example
ObjectLockConfiguration config =
    minioClient.getObjectLockConfiguration(
	    GetObjectLockConfigurationArgs.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());
}
listBuckets(ListBucketsArgs args)
public List<Bucket> listBuckets(ListBucketsArgs args) [Javadoc]
Lists bucket information of all buckets.
Parameters
| Parameter | Type | Description | 
|---|---|---|
| 
 | Arguments. | 
| Returns | 
|---|
| List<Bucket> - List of bucket information. | 
Example
List<Bucket> bucketList =
    minioClient.listBuckets(ListBuckets.builder().extraHeaders(headers).build());
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 | 
|---|---|---|
| 
 | 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());
    }
  }
}
listObjects(ListObjectsArgs args)
public Iterable<Result<Item>> listObjects(ListObjectsArgs args) [Javadoc]
Lists object information of a bucket.
Parameters
| Parameter | Type | Description | 
|---|---|---|
| 
 | 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 whose 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 whose 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 | 
|---|---|---|
| 
 | 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 | 
|---|---|---|
| 
 | Arguments. | 
Example
minioClient.removeBucket(RemoveBucketArgs.builder().bucket(bucketName).build());
setBucketEncryption(SetBucketEncryptionArgs args)
public void setBucketEncryption(SetBucketEncryptionArgs args) [Javadoc]
Sets encryption configuration of a bucket.
Parameters
| Parameter | Type | Description | 
|---|---|---|
| 
 | Arguments. | 
Example
minioClient.setBucketEncryption(
    SetBucketEncryptionArgs.builder().bucket("my-bucketname").config(config).build());
setBucketLifecycle(SetBucketLifecycleArgs args)
public void setBucketLifecycle(SetBucketLifecycleArgs args) [Javadoc]
Sets lifecycle configuration to a bucket.
Parameters
| Parameter | Type | Description | 
|---|---|---|
| 
 | Arguments. | 
Example
List<LifecycleRule> rules = new LinkedList<>();
rules.add(
    new LifecycleRule(
        Status.ENABLED,
        null,
        null,
        new RuleFilter("documents/"),
        "rule1",
        null,
        null,
        new Transition((ZonedDateTime) null, 30, "GLACIER")));
rules.add(
    new LifecycleRule(
        Status.ENABLED,
        null,
        new Expiration((ZonedDateTime) null, 365, null),
        new RuleFilter("logs/"),
        "rule2",
        null,
        null,
        null));
LifecycleConfiguration config = new LifecycleConfiguration(rules);
minioClient.setBucketLifecycle(
    SetBucketLifecycleArgs.builder().bucket("my-bucketname").config(config).build());
setBucketNotification(SetBucketNotificationArgs args)
public void setBucketNotification(SetBucketNotificationArgs args) [Javadoc]
Sets notification configuration to a bucket.
Parameters
| Parameter | Type | Description | 
|---|---|---|
| 
 | 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 | 
|---|---|---|
| 
 | 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());
setBucketReplication(SetBucketReplicationArgs args)
public void setBucketReplication(SetBucketReplicationArgs args) [Javadoc]
Sets bucket replication configuration to a bucket.
Parameters
| Parameter | Type | Description | 
|---|---|---|
| 
 | Arguments. | 
Example
Map<String, String> tags = new HashMap<>();
tags.put("key1", "value1");
tags.put("key2", "value2");
ReplicationRule rule =
    new ReplicationRule(
        new DeleteMarkerReplication(Status.DISABLED),
        new ReplicationDestination(
            null, null, "REPLACE-WITH-ACTUAL-DESTINATION-BUCKET-ARN", null, null, null, null),
        null,
        new RuleFilter(new AndOperator("TaxDocs", tags)),
        "rule1",
        null,
        1,
        null,
        Status.ENABLED);
List<ReplicationRule> rules = new LinkedList<>();
rules.add(rule);
ReplicationConfiguration config =
    new ReplicationConfiguration("REPLACE-WITH-ACTUAL-ROLE", rules);
minioClient.setBucketReplication(
    SetBucketReplicationArgs.builder().bucket("my-bucketname").config(config).build());
setBucketVersioning(SetBucketVersioningArgs args)
public void setBucketVersioning(SetBucketVersioningArgs args) [Javadoc]
Sets versioning configuration of a bucket.
Parameters
| Parameter | Type | Description | 
|---|---|---|
| 
 | Arguments. | 
Example
minioClient.setBucketVersioning(
    SetBucketVersioningArgs.builder().bucket("my-bucketname").config(config).build());
setObjectLockConfiguration(SetObjectLockConfigurationArgs args)
public void setObjectLockConfiguration(SetObjectLockConfigurationArgs args) [Javadoc]
Sets object-lock configuration in a bucket.
Parameters
| Parameter | Type | Description | 
|---|---|---|
| 
 | Arguments. | 
Example
ObjectLockConfiguration config =
    new ObjectLockConfiguration(RetentionMode.COMPLIANCE, new RetentionDurationDays(100));
minioClient.setObjectLockConfiguration(
    SetObjectLockConfigurationArgs.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 | 
|---|---|---|
| 
 | 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.
Map<String, String> userMetadata = new HashMap<>();
userMetadata.put("My-Project", "Project One");
minioClient.composeObject(
   ComposeObjectArgs.builder()
     .bucket("my-bucketname")
     .object("my-objectname")
     .sources(sourceObjectList)
     .userMetadata(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)
     .userMetadata(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 | 
|---|---|---|
| 
 | 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")
        .source(
            CopySource.builder()
                .bucket("my-source-bucketname")
                .object("my-objectname")
                .build())
        .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")
        .source(
            CopySource.builder()
                .bucket("my-source-bucketname")
                .object("my-source-objectname")
                .build())
        .build());
// Create object "my-objectname" in bucket "my-bucketname" with SSE-KMS server-side
// encryption by copying from object "my-objectname" in bucket "my-source-bucketname".
minioClient.copyObject(
    CopyObjectArgs.builder()
        .bucket("my-bucketname")
        .object("my-objectname")
        .source(
            CopySource.builder()
                .bucket("my-source-bucketname")
                .object("my-objectname")
                .build())
        .sse(sseKms) // Replace with actual key.
        .build());
// Create object "my-objectname" in bucket "my-bucketname" with SSE-S3 server-side
// encryption by copying from object "my-objectname" in bucket "my-source-bucketname".
minioClient.copyObject(
    CopyObjectArgs.builder()
        .bucket("my-bucketname")
        .object("my-objectname")
        .source(
            CopySource.builder()
                .bucket("my-source-bucketname")
                .object("my-objectname")
                .build())
        .sse(sseS3) // Replace with actual key.
        .build());
// Create object "my-objectname" in bucket "my-bucketname" with SSE-C server-side encryption
// by copying from object "my-objectname" in bucket "my-source-bucketname".
minioClient.copyObject(
    CopyObjectArgs.builder()
        .bucket("my-bucketname")
        .object("my-objectname")
        .source(
            CopySource.builder()
                .bucket("my-source-bucketname")
                .object("my-objectname")
                .build())
        .sse(ssec) // Replace with actual key.
        .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")
        .source(
            CopySource.builder()
                .bucket("my-source-bucketname")
                .object("my-source-objectname")
                .ssec(ssec) // Replace with actual key.
                .build())
        .build());
// Create object "my-objectname" in bucket "my-bucketname" with custom headers conditionally
// by copying from object "my-objectname" in bucket "my-source-bucketname".
minioClient.copyObject(
    CopyObjectArgs.builder()
        .bucket("my-bucketname")
        .object("my-objectname")
        .source(
            CopySource.builder()
                .bucket("my-source-bucketname")
                .object("my-objectname")
                .matchETag(etag) // Replace with actual etag.
                .build())
        .headers(headers) // Replace with actual headers.
        .build());
disableObjectLegalHold(DisableObjectLegalHoldArgs args)
public void disableObjectLegalHold(DisableObjectLegalHoldArgs args) [Javadoc]
Disables legal hold on an object.
Parameters
| Parameter | Type | Description | 
|---|---|---|
| 
 | 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 | 
|---|---|---|
| 
 | 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 | 
|---|---|---|
| 
 | 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 | 
|---|---|---|
| 
 | 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 | 
|---|---|---|
| 
 | 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());
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 | 
|---|---|---|
| 
 | Arguments. | 
| Returns | 
|---|
| String - URL string. | 
Example
// 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<String, String> reqParams = new HashMap<String, String>();
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<String, String> reqParams = new HashMap<String, String>();
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);
isObjectLegalHoldEnabled(IsObjectLegalHoldEnabledArgs args)
public boolean isObjectLegalHoldEnabled(IsObjectLegalHoldEnabledArgs args) [Javadoc]
Returns true if legal hold is enabled on an object.
Parameters
| Parameter | Type | Description | 
|---|---|---|
| 
 | 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");
}
getPresignedPostFormData(PostPolicy policy)
public Map<String,String> getPresignedPostFormData(PostPolicy policy) [Javadoc]
Gets form-data of PostPolicy of an object to upload its data using POST method.
Parameters
| Parameter | Type | Description | 
|---|---|---|
| 
 | Post policy of an object. | 
| Returns | 
|---|
| Map<String, String> - Contains form-data to upload an object using POST method. | 
Example
// 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<String, String> 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<String, String> 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");
}
putObject(PutObjectArgs args)
public ObjectWriteResponse putObject(PutObjectArgs args) [Javadoc]
Uploads given stream as object in bucket.
Parameters
| Parameter | Type | Description | 
|---|---|---|
| 
 | 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 | 
|---|---|---|
| 
 | 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());
uploadSnowballObjects(UploadSnowballObjectsArgs args)
public void uploadSnowballObjects(UploadSnowballObjectsArgs args) [Javadoc]
Uploads multiple objects in a single put call. It is done by creating intermediate TAR file optionally compressed which is uploaded to S3 service.
Parameters
| Parameter | Type | Description | 
|---|---|---|
| 
 | Arguments. | 
Example
List<SnowballObject> objects = new ArrayList<SnowballObject>();
objects.add(
    new SnowballObject(
        "my-object-one",
        new ByteArrayInputStream("hello".getBytes(StandardCharsets.UTF_8)),
        5,
        null));
objects.add(
    new SnowballObject(
        "my-object-two",
        new ByteArrayInputStream("java".getBytes(StandardCharsets.UTF_8)),
        4,
        null));
minioClient.uploadSnowballObjects(
    UploadSnowballObjectsArgs.builder().bucket("my-bucketname").objects(objects).build());
removeObject(RemoveObjectArgs args)
public void removeObject(RemoveObjectArgs args) [Javadoc]
Removes an object.
Parameters
| Parameter | Type | Description | 
|---|---|---|
| 
 | 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 | 
|---|---|---|
| 
 | 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());
}
restoreObject(RestoreObjectArgs args)
public void restoreObject(RestoreObjectArgs args) [Javadoc]
Restores an object.
Parameters
| Parameter | Type | Description | 
|---|---|---|
| 
 | Arguments. | 
Example
// Restore object.
minioClient.restoreObject(
    RestoreObjectArgs.builder()
        .bucket("my-bucketname")
        .object("my-objectname")
        .request(new RestoreRequest(null, null, null, null, null, null))
        .build());
// Restore versioned object.
minioClient.restoreObject(
    RestoreObjectArgs.builder()
        .bucket("my-bucketname")
        .object("my-versioned-objectname")
        .versionId("my-versionid")
        .request(new RestoreRequest(null, null, null, null, null, null))
        .build());
selectObjectContent(SelectObjectContentArgs args)
public SelectResponseStream selectObjectContent(SelectObjectContentArgs args) [Javadoc]
Selects content of a object by SQL expression.
Parameters
| Parameter | Type | Description | 
|---|---|---|
| 
 | 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 | 
|---|---|---|
| 
 | 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());
statObject(StatObjectArgs args)
public ObjectStat statObject(StatObjectArgs args) [Javadoc]
Gets object information and metadata of an object.
Parameters
| Parameter | Type | Description | 
|---|---|---|
| 
 | 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());
