Java Client API Reference Slack

Initialize MinIO Client object.

MinIO

MinioClient minioClient = new MinioClient("https://play.min.io",
    "Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");

AWS S3

MinioClient s3Client = new MinioClient("https://s3.amazonaws.com",
    "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY");
Bucket operations Object operations
bucketExists composeObject
deleteBucketLifeCycle copyObject
disableVersioning disableObjectLegalHold
enableVersioning enableObjectLegalHold
getBucketLifeCycle getObject
getBucketNotification getObjectRetention
getBucketPolicy getObjectUrl
getDefaultRetention getPresignedObjectUrl
listBuckets isObjectLegalHoldEnabled
listenBucketNotification listObjects
listIncompleteUploads presignedGetObject
makeBucket presignedPostPolicy
removeAllBucketNotification presignedPutObject
removeBucket putObject
removeIncompleteUpload removeObject
setBucketLifeCycle removeObjects
setBucketNotification selectObjectContent
setBucketPolicy setObjectRetention
setDefaultRetention statObject

1. Constructors

public MinioClient(String endpoint) throws InvalidEndpointException, InvalidPortException [Javadoc]
Creates MinIO client object with given endpoint using anonymous access.
public MinioClient(URL url) throws InvalidEndpointException, InvalidPortException [Javadoc]
Creates MinIO client object with given url using anonymous access.
public MinioClient(okhttp3.HttpUrl url) throws InvalidEndpointException, InvalidPortException [Javadoc]
Creates MinIO client object with given HttpUrl object using anonymous access.
public MinioClient(String endpoint, String accessKey, String secretKey) throws InvalidEndpointException, InvalidPortException [Javadoc]
Creates MinIO client object with given endpoint, access key and secret key.
public MinioClient(String endpoint, int port, String accessKey, String secretKey) throws InvalidEndpointException, InvalidPortException [Javadoc]
Creates MinIO client object with given endpoint, port, access key and secret key using secure (HTTPS) connection.
public MinioClient(String endpoint, String accessKey, String secretKey, boolean secure) throws InvalidEndpointException, InvalidPortException [Javadoc]
Creates MinIO client object with given endpoint, access key and secret key using secure (HTTPS) connection.
public MinioClient(String endpoint, int port, String accessKey, String secretKey, boolean secure) throws InvalidEndpointException, InvalidPortException [Javadoc]
Creates MinIO client object using given endpoint, port, access key, secret key and secure option.
public MinioClient(okhttp3.HttpUrl url, String accessKey, String secretKey) throws InvalidEndpointException, InvalidPortException [Javadoc]
Creates MinIO client object with given URL object, access key and secret key.
public MinioClient(URL url, String accessKey, String secretKey) throws InvalidEndpointException, InvalidPortException [Javadoc]
Creates MinIO client object with given URL object, access key and secret key.
public MinioClient(String endpoint, String accessKey, String secretKey, String region) throws InvalidEndpointException, InvalidPortException [Javadoc]
Creates MinIO client object with given URL object, access key and secret key.
public MinioClient(String endpoint, int port, String accessKey, String secretKey, String region, boolean secure) throws InvalidEndpointException, InvalidPortException [Javadoc]
Creates MinIO client object using given endpoint, port, access key, secret key, region and secure option.
public MinioClient(String endpoint, int port, String accessKey, String secretKey, String region, boolean secure, okhttp3.OkHttpClient httpClient) throws InvalidEndpointException, InvalidPortException [Javadoc]
Creates MinIO client object using given endpoint, port, access key, secret key, region and secure option.

Parameters

Parameter Type Description
endpoint String Endpoint is an URL, domain name, IPv4 address or IPv6 address of S3 service.
Examples:
https://s3.amazonaws.com
https://play.min.io
https://play.min.io:9000
localhost
play.min.io
url URL Endpoint as URL object.
url okhttp3.HttpUrl Endpoint as okhttp3.HttpUrl object.
port int (Optional) TCP/IP port number. 80 and 443 are used as defaults for HTTP and HTTPS.
accessKey String (Optional) Access key (aka user ID) of your account in S3 service.
secretKey String (Optional) Secret Key (aka password) of your account in S3 service.
secure boolean (Optional) Flag to indicate to use secure connection to S3 service or not.
region String (Optional) Region name of buckets in S3 service.
httpClient okhttp3.OkHttpClient (Optional) Custom HTTP client object.

Example

MinIO

// 1. Create client to S3 service 'play.min.io' at port 443 with TLS security
// for anonymous access.
MinioClient minioClient = new MinioClient("https://play.min.io");

// 2. Create client to S3 service 'play.min.io' at port 443 with TLS security
// using URL object for anonymous access.
MinioClient minioClient = new MinioClient(new URL("https://play.min.io"));

// 3. Create client to S3 service 'play.min.io' at port 9000 with TLS security
// using okhttp3.HttpUrl object for anonymous access.
MinioClient minioClient = new MinioClient(new HttpUrl.parse("https://play.min.io:9000"));

// 4. Create client to S3 service 'play.min.io' at port 443 with TLS security
// for authenticated access.
MinioClient minioClient = new MinioClient("https://play.min.io",
    "Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");

// 5. Create client to S3 service 'play.min.io' at port 9000 with non-TLS security
// for authenticated access.
MinioClient minioClient = new MinioClient("play.min.io", 9000,
    "Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");

// 6. Create client to S3 service 'play.min.io' at port 9000 with TLS security
// for authenticated access.
MinioClient minioClient = new MinioClient("play.min.io", 9000,
    "Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG", true);

// 7. Create client to S3 service 'play.min.io' at port 443 with TLS security
// using URL object for authenticated access.
MinioClient minioClient = new MinioClient(new URL("https://play.min.io"),
     "Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");

// 8. Create client to S3 service 'play.min.io' at port 443 with TLS security
// using okhttp3.HttpUrl object for authenticated access.
MinioClient minioClient = new MinioClient(HttpUrl.parse("https://play.min.io"),
    "Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");

// 9. Create client to S3 service 'play.min.io' at port 443 with TLS security
// and region 'us-west-1' for authenticated access.
MinioClient minioClient = new MinioClient("https://play.min.io",
    "Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG", "us-west-1");

// 10. Create client to S3 service 'play.min.io' at port 9000 with TLS security
// and region 'eu-east-1' for authenticated access.
MinioClient minioClient = new MinioClient("play.min.io", 9000,
    "Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG", "eu-east-1", true);

// 11. 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 = new MinioClient("play.min.io", 9000,
    "Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG", "eu-east-1",
    true, customHttpClient);

AWS S3

// 1. Create client to S3 service 's3.amazonaws.com' at port 443 with TLS security
// for anonymous access.
MinioClient s3Client = new MinioClient("https://s3.amazonaws.com");

// 2. Create client to S3 service 's3.amazonaws.com' at port 443 with TLS security
// using URL object for anonymous access.
MinioClient minioClient = new MinioClient(new URL("https://s3.amazonaws.com"));

// 3. Create client to S3 service 's3.amazonaws.com' at port 9000 with TLS security
// using okhttp3.HttpUrl object for anonymous access.
MinioClient s3Client = new MinioClient(new HttpUrl.parse("https://s3.amazonaws.com"));

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

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

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

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

// 8. Create client to S3 service 's3.amazonaws.com' at port 80 with non-TLS security
// using URL object for authenticated access.
MinioClient s3Client = new MinioClient(new URL("s3.amazonaws.com"),
    "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY");

// 9. Create client to S3 service 's3.amazonaws.com' at port 80 with non-TLS security
// using okhttp3.HttpUrl object for authenticated access.
MinioClient s3Client = new MinioClient(HttpUrl.parse("s3.amazonaws.com"),
    "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY");

// 10. 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 = new MinioClient("s3.amazonaws.com",
    "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", "us-west-1");

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

// 12. 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 = new MinioClient("s3.amazonaws.com", 443,
    "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", "eu-central-1", true, customHttpClient);

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 is 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 is 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(String bucketName)

public boolean bucketExists(String bucketName) [Javadoc]

Checks if a bucket exists.

Parameters
| Parameter | Type | Description |
|:---------------|:---------|:--------------------|
| bucketName | String | Name of the bucket. |

Returns
boolean: true if the bucket exists.

Example

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

deleteBucketLifeCycle(String bucketName)

private void deleteBucketLifeCycle(String bucketName) [Javadoc]

Delete the lifecycle of the bucket.

Parameters
| Parameter | Type | Description |
|:---------------|:---------|:--------------------|
| bucketName | String | Name of the bucket. |

Example

minioClient.deleteBucketLifeCycle("my-bucketname");

disableVersioning(String bucketName)

public void disableVersioning(String bucketName) [Javadoc]

Object versioning is disabled in bucketName.

Parameters
| Parameter | Type | Description |
|:---------------|:---------|:--------------------|
| bucketName | String | Name of the bucket. |

Example

minioClient.disableVersioning("my-bucketname");

enableVersioning(String bucketName)

public void enableVersioning(String bucketName) [Javadoc]

Object versioning is enabled in bucketName.

Parameters

Parameter Type Description
bucketName String Name of the bucket.

Example

minioClient.enableVersioning("my-bucketname");

getBucketLifeCycle(String bucketName)

public String getBucketLifeCycle(String bucketName) [Javadoc]

Get the lifecycle of the bucket.

Parameters
| Parameter | Type | Description |
|:---------------|:---------|:--------------------|
| bucketName | String | Name of the bucket. |

Returns
String: contains lifecycle configuration.

Example

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

getBucketNotification(String bucketName)

public NotificationConfiguration getBucketNotification(String bucketName) [Javadoc]

Get bucket notification configuration.

Parameters
| Parameter | Type | Description |
|:---------------|:---------|:--------------------|
| bucketName | String | Name of the bucket. |

Returns
NotificationConfiguration: NotificationConfiguration object.

Example

NotificationConfiguration config = minioClient.getBucketNotification("my-bucketname");
System.out.println(config);

getBucketPolicy(String bucketName)

public String getBucketPolicy(String bucketName) [Javadoc]

Get bucket policy for a bucket.

Parameters
| Parameter | Type | Description |
|:---------------|:---------|:--------------------|
| bucketName | String | Name of the bucket. |

Returns
String: Bucket policy JSON string.

Example

String config = minioClient.getBucketPolicy("myBucket");
System.out.println("Bucket policy: " + config);

getDefaultRetention(String bucketName)

public ObjectLockConfiguration getDefaultRetention(String bucketName) [Javadoc]

Get default retention of bucket.

Parameters

Parameter Type Description
bucketName String Name of the bucket.
Returns
ObjectLockConfiguration: ObjectLockConfiguration object.

Example

// bucket must be created with object lock enabled.
s3Client.makeBucket("my-bucketname", null, true);
ObjectLockConfiguration config = s3Client.getDefaultRetention("my-bucketname");
System.out.println("Mode: " + config.mode());
System.out.println("Duration: " + config.duration().duration() + " " + config.duration().unit());

listBuckets()

public List<Bucket> listBuckets() [Javadoc]

Lists all buckets.

Returns
List<Bucket> : List of Bucket object.

Example

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

listenBucketNotification(String bucketName, String prefix, String suffix, String[] events)

public CloseableIterator<Result<NotificationRecords>> listenBucketNotification(String bucketName, String prefix, String suffix, String[] events) [Javadoc]

Listen events of object prefix and suffix in bucket.

Parameters
| Parameter | Type | Description |
|:---------------|:-----------|:--------------------------------------------|
| bucketName | String | Name of the bucket. |
| prefix | String | Listen events of object starts with prefix. |
| suffix | String | Listen events of object ends with suffix. |
| events | String[] | Events to listen. |

Returns
CloseableIterator<Result<NotificationRecords>>: closable iterator of Result NotificationRecords.

Example

String[] events = {"s3:ObjectCreated:*", "s3:ObjectAccessed:*"};
try (CloseableIterator<Result<NotificationInfo>> ci =
    minioClient.listenBucketNotification("bcketName", "", "", events)) {
  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(String bucketName)

public Iterable<Result<Upload>> listIncompleteUploads(String bucketName) [Javadoc]

Lists partially uploaded objects in a bucket.

Parameters
| Parameter | Type | Description |
|:---------------|:---------|:--------------------|
| bucketName | String | Name of the bucket. |

Returns
Iterable<Result<Upload>>: an iterator of Upload.

Example

Iterable<Result<Upload>> results = minioClient.listIncompleteUploads("my-bucketname");
for (Result<Upload> result : results) {
  Upload upload = result.get();
  System.out.println(upload.uploadId() + ", " + upload.objectName());
}

listIncompleteUploads(String bucketName, String prefix)

public Iterable<Result<Upload>> listIncompleteUploads(String bucketName, String prefix) [Javadoc]

Lists incomplete uploads of objects in given bucket and prefix.

Parameters
| Parameter | Type | Description |
|:---------------|:---------|:---------------------------------|
| bucketName | String | Name of the bucket. |
| prefix | String | List objects starts with prefix. |

Returns
Iterable<Result<Upload>>: an iterator of Upload.

Example

Iterable<Result<Upload>> myObjects = minioClient.listIncompleteUploads("my-bucketname", "my-obj");
for (Result<Upload> result : results) {
  Upload upload = result.get();
  System.out.println(upload.uploadId() + ", " + upload.objectName());
}

listIncompleteUploads(String bucketName, String prefix, boolean recursive)

public Iterable<Result<Upload>> listIncompleteUploads(String bucketName, String prefix, boolean recursive) [Javadoc]

Lists partially uploaded objects in a bucket.

Parameters
| Param | Type | Description |
|:---------------|:----------|:---------------------------------------------------------------|
| bucketName | String | Name of the bucket. |
| prefix | String | List objects starts with prefix. |
| recursive | boolean | List objects recursively; else emulates a directory structure. |

Returns
Iterable<Result<Upload>>: an iterator of Upload.

Example

Iterable<Result<Upload>> myObjects = minioClient.listIncompleteUploads("my-bucketname", "my-obj", true);
for (Result<Upload> result : results) {
  Upload upload = result.get();
  System.out.println(upload.uploadId() + ", " + upload.objectName());
}

listObjects(String bucketName)

public Iterable<Result<Item>> listObjects(String bucketName) [Javadoc]

Lists object information in given bucket.

Parameters
| Parameter | Type | Description |
|:---------------|:---------|:--------------------|
| bucketName | String | Name of the bucket. |

Returns
Iterable<Result<Item>>: an iterator of Result Items.

Example

Iterable<Result<Item>> results = minioClient.listObjects("my-bucketname");
for (Result<Item> result : results) {
  Item item = result.get();
  System.out.println(item.lastModified() + ", " + item.size() + ", " + item.objectName());
}

listObjects(String bucketName, String prefix)

public Iterable<Result<Item>> listObjects(String bucketName, String prefix)) [Javadoc]

Lists object information in given bucket and prefix.

Parameters
| Parameter | Type | Description |
|:---------------|:---------|:---------------------------------|
| bucketName | String | Name of the bucket. |
| prefix | String | List objects starts with prefix. |

Returns
Iterable<Result<Item>>: an iterator of Result Items.

Example

Iterable<Result<Item>> results = minioClient.listObjects("my-bucketname", "my-obj");
for (Result<Item> result : results) {
  Item item = result.get();
  System.out.println(item.lastModified() + ", " + item.size() + ", " + item.objectName());
}

listObjects(String bucketName, String prefix, boolean recursive)

public Iterable<Result<Item>> listObjects(String bucketName, String prefix, boolean recursive) [Javadoc]

Lists object information as Iterable in given bucket, prefix and recursive flag.

Parameters
| Parameter | Type | Description |
|:---------------|:----------|:---------------------------------------------------------------|
| bucketName | String | Name of the bucket. |
| prefix | String | List objects starts with prefix. |
| recursive | boolean | List objects recursively; else emulates a directory structure. |

Returns
Iterable<Result<Item>>: an iterator of Result Items.

Example

Iterable<Result<Item>> results = minioClient.listObjects("my-bucketname", "my-obj", true);
for (Result<Item> result : results) {
  Item item = result.get();
  System.out.println(item.lastModified() + ", " + item.size() + ", " + item.objectName());
}

listObjects(String bucketName, String prefix, boolean recursive, boolean useVersion1)

public Iterable<Result<Item>> listObjects(String bucketName, String prefix, boolean recursive, boolean useVersion1) [Javadoc]

Lists all objects in a bucket.

Parameters
| Parameter | Type | Description |
|:----------------|:----------|:---------------------------------------------------------------|
| bucketName | String | Name of the bucket. |
| prefix | String | List objects starts with prefix. |
| recursive | boolean | List objects recursively; else emulates a directory structure. |
| useVersion1 | boolean | when true, version 1 of REST API is used. |

Returns
Iterable<Result<Item>>: an iterator of Result Items.

Example

Iterable<Result<Item>> results = minioClient.listObjects("my-bucketname", "my-obj", true, true);
for (Result<Item> result : results) {
  Item item = result.get();
  System.out.println(item.lastModified() + ", " + item.size() + ", " + item.objectName());
}

makeBucket(String bucketName)

public void makeBucket(String bucketName) [Javadoc]

Creates a new bucket with default region.

Parameters
| Parameter | Type | Description |
|:---------------|:---------|:--------------------|
| bucketName | String | Name of the bucket. |

Example

minioClient.makeBucket("my-bucketname");

makeBucket(String bucketName, String region)

public void makeBucket(String bucketName, String region) [Javadoc]

Creates a new bucket with given region.

Parameters
| Parameter | Type | Description |
|:---------------|:---------|:--------------------------------------------|
| bucketName | String | Name of the bucket. |
| region | String | Region in which the bucket will be created. |

Example

minioClient.makeBucket("my-bucketname", "eu-west-1");

makeBucket(String bucketName, String region, boolean objectLock)

public void makeBucket(String bucketName, String region, boolean objectLock) [Javadoc]

Creates a new bucket with object lock functionality enabled.

Parameters
| Parameter | Type | Description |
|:---------------|:----------|:-----------------------------------------------|
| bucketName | String | Name of the bucket. |
| region | String | Region in which the bucket will be created. |
| objectLock | boolean | Create bucket with object lock feature or not. |

Example

minioClient.makeBucket("my-bucketname", "us-west-2", true);

removeAllBucketNotification(String bucketName)

public void removeAllBucketNotification(String bucketName) [Javadoc]

Remove all notification configuration from a bucket.

View Javadoc

Parameters
| Parameter | Type | Description |
|:---------------|:---------|:--------------------|
| bucketName | String | Name of the bucket. |

Example

minioClient.removeAllBucketNotification("my-bucketname");

removeBucket(String bucketName)

public void removeBucket(String bucketName) [Javadoc]

Removes an empty bucket.

Parameters
| Parameter | Type | Description |
|:---------------|:---------|:--------------------|
| bucketName | String | Name of the bucket. |

Example

minioClient.removeBucket("my-bucketname");

removeIncompleteUpload(String bucketName, String objectName)

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

Removes a partially uploaded object.

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

Example

minioClient.removeIncompleteUpload("my-bucketname", "my-objectname");

setBucketLifeCycle(String bucketName, String lifeCycle)

public void setBucketLifeCycle(String bucketName, String lifeCycle) [Javadoc]

Set a life cycle on bucket.

Parameters
| Parameter | Type | Description |
|:---------------|:---------|:---------------------------------------|
| bucketName | String | Name of the bucket. |
| lifeCycle | String | Life cycle configuraion as XML string. |

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("my-bucketname", lifeCycleXml);

setBucketNotification(String bucketName, NotificationConfiguration notificationConfiguration)

public void setBucketNotification(String bucketName, NotificationConfiguration notificationConfiguration) [Javadoc]

Set bucket notification configuration.

Parameters

Parameter Type Description
bucketName String Name of the bucket.
notificationConfiguration NotificationConfiguration Notification configuration to be set.

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("my-bucketname", config);

setBucketPolicy(String bucketName, String policy)

public void setBucketPolicy(String bucketName, String policy) [Javadoc]

Set a policy on bucket.

Parameters

Parameter Type Description
bucketName String Name of the bucket.
policy String Bucket policy as JSON string.

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("my-bucketname", policyJson);

setDefaultRetention(String bucketName, ObjectLockConfiguration config)

public void setDefaultRetention(String bucketName, ObjectLockConfiguration config) [Javadoc]

Set default retention on bucket.

Parameters
| Parameter | Type | Description |
|:---------------|:----------------------------|:---------------------------|
| bucketName | String | Name of the bucket. |
| config | ObjectLockConfiguration | Object lock Configuration. |

Example

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

3. Object operations

composeObject(String bucketName, String objectName, List sources, Map headerMap, ServerSideEncryption sse)

public void composeObject(String bucketName, String objectName, List<ComposeSource> sources, Map<String,String> headerMap, ServerSideEncryption sse) [Javadoc]

Creates a new Object by combining different source objects.

Parameters
| Param | Type | Description |
|:---------------|:-------------------------|:-----------------------------------|
| bucketName | String | Name of the bucket. |
| objectName | String | Object name to be created. |
| sources | List<ComposeSource> | List of compose sources. |
| headerMap | Map | (Optional) User metadata. |
| sse | ServerSideEncryption | (Optional) Server-side encryption. |

Example

List<ComposeSource> sourceObjectList = new ArrayList<ComposeSource>();
sourceObjectList.add(new ComposeSource("my-job-bucket", "my-objectname-part-one"));
sourceObjectList.add(new ComposeSource("my-job-bucket", "my-objectname-part-two"));
sourceObjectList.add(new ComposeSource("my-job-bucket", "my-objectname-part-three"));
minioClient.composeObject("my-bucketname", "my-objectname", sourceObjectList, null, null);

copyObject(String bucketName, String objectName, Map headerMap, ServerSideEncryption sse, String srcBucketName, String srcObjectName, ServerSideEncryption srcSse, CopyConditions copyConditions)

public void copyObject(String bucketName, String objectName, Map<String,String> headerMap, ServerSideEncryption sse, String srcBucketName, String srcObjectName, ServerSideEncryption srcSse, CopyConditions copyConditions) [Javadoc]

Create object by copying from source object in source bucket.

Parameters
| Parameter | Type | Description |
|:-------------------|:-------------------------|:-------------------------------------------|
| bucketName | String | Bucket name. |
| objectName | String | Object name to be created. |
| headerMap | Map | (Optional) User metadata. |
| sse | ServerSideEncryption | (Optional) Server-side encryption. |
| srcBucketName | String | Source bucket name. |
| srcObjectName | String | (Optional) Source object name. |
| srcSse | ServerSideEncryption | (Optional) Source Server-side encryption. |
| copyConditions | CopyConditions | (Optional) Conditiions to be used to copy. |

Example

minioClient.copyObject("my-bucketname", "my-objectname", null, null, "my-source-bucketname", null, null, null);

disableObjectLegalHold(String bucketName, String objectName, String versionId)

public void disableObjectLegalHold(String bucketName, String objectName, String versionId) [Javadoc]

Disables legal hold on an object.

Parameters
| Parameter | Type | Description |
|:---------------|:---------|:--------------------------|
| bucketName | String | Bucket name. |
| objectName | String | Object name. |
| versionId | String | Version ID of the object. |

Example

minioClient.disableObjectLegalHold("my-bucketname", "my-objectName", null);

enableObjectLegalHold(String bucketName, String objectName, String versionId)

public void enableObjectLegalHold(String bucketName, String objectName, String versionId) [Javadoc]

Enables legal hold on an object.

Parameters
| Parameter | Type | Description |
|:---------------|:---------|:---------------------------|
| bucketName | String | Name of the bucket. |
| objectName | String | Object name to be created. |
| versionId | String | Version ID of the object. |

Example

minioClient.enableObjectLegalHold("my-bucketname", "my-objectname", null);

getObject(String bucketName, String objectName)

public InputStream getObject(String bucketName, String objectName) [Javadoc]

Downloads an object as a stream.

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

Returns
InputStream: InputStream containing object data.

Example

InputStream stream = minioClient.getObject("my-bucketname", "my-objectname");

getObject(String bucketName, String objectName, long offset)

public InputStream getObject(String bucketName, String objectName, long offset) [Javadoc]

Gets object's data starting from given offset as InputStream in the given bucket. The InputStream must be closed after use else the connection will remain open.

Parameters
| Parameter | Type | Description |
|:---------------|:---------|:------------------------------------|
| bucketName | String | Name of the bucket. |
| objectName | String | Object name in the bucket. |
| offset | long | Start byte position of object data. |

Returns
InputStream: InputStream containing object data.

Example

InputStream stream = minioClient.getObject("my-bucketname", "my-objectname", 1024L);

getObject(String bucketName, String objectName, long offset, Long length)

public InputStream getObject(String bucketName, String objectName, long offset, Long length) [Javadoc]

Downloads the specified range bytes of an object as a stream.

Parameters
| Parameter | Type | Description |
|:---------------|:---------|:-------------------------------------------------------|
| bucketName | String | Name of the bucket. |
| objectName | String | Object name in the bucket. |
| offset | long | Start byte position of object data. |
| length | Long | (Optional) Number of bytes of object data from offset. |

Returns
InputStream: InputStream containing object data.

Example

InputStream stream = minioClient.getObject("my-bucketname", "my-objectname", 1024L, 4096L);

getObject(String bucketName, String objectName, ServerSideEncryption sse)

public InputStream getObject(String bucketName, String objectName, ServerSideEncryption sse) [Javadoc]

Gets entire server-side encrypted object's data as InputStream in given bucket. The InputStream must be closed after use else the connection will remain open.

Parameters
| Parameter | Type | Description |
|:---------------|:-------------------------|:---------------------------|
| bucketName | String | Name of the bucket. |
| objectName | String | Object name in the bucket. |
| sse | ServerSideEncryption | Server-side encryption. |

Returns
InputStream: InputStream containing object data.

Example

InputStream stream = minioClient.getObject("my-bucketname", "my-objectname", sse);

getObject(String bucketName, String objectName, Long offset, Long length, ServerSideEncryption sse)

public InputStream getObject(String bucketName, String objectName, Long offset, Long length, ServerSideEncryption sse) [Javadoc]

Gets specified range bytes of server-side encrypted object's data as InputStream in given bucket. The InputStream must be closed after use else the connection will remain open.

Parameters
| Parameter | Type | Description |
|:---------------|:-------------------------|:-------------------------------------------------------|
| bucketName | String | Name of the bucket. |
| objectName | String | Object name in the bucket. |
| offset | long | Start byte position of object data. |
| length | Long | (Optional) Number of bytes of object data from offset. |
| sse | ServerSideEncryption | (Optional) Server-side encryption. |

Returns
InputStream: InputStream containing object data.

Example

InputStream stream = minioClient.getObject("my-bucketname", "my-objectname", 1024L, 4096L, sse);

getObject(String bucketName, String objectName, String fileName)

public void getObject(String bucketName, String objectName, String fileName) [Javadoc]

Downloads object in bucket to given file name.

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

Example

minioClient.getObject("my-bucketname", "my-objectname", "my-object-file");

getObject(String bucketName, String objectName, ServerSideEncryption sse, String fileName)

public void getObject(String bucketName, String objectName, ServerSideEncryption sse, String fileName) [Javadoc]

Downloads server-side encrypted object in bucket to given file name.

Parameters
| Parameter | Type | Description |
|:---------------|:-------------------------|:---------------------------|
| bucketName | String | Name of the bucket. |
| objectName | String | Object name in the bucket. |
| sse | ServerSideEncryption | Server-side encryption. |
| fileName | String | File name. |

Example

minioClient.getObject("my-bucketname", "my-objectname", sse, "my-object-file");

getObjectRetention(String bucketName, String objectName, String versionId)

public Retention getObjectRetention(String bucketName, String objectName, String versionId) [Javadoc]

Returns retention set on a given object.

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

Returns
Retention: Retention object

Example

Retention retention = s3Client.getObjectRetention("my-bucketname", "my-objectname", null);
System.out.println("mode: " + retention.mode() + "until: " + retention.retainUntilDate());

getObjectUrl(String bucketName, String objectName)

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

Gets object's URL in given bucket.

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

Returns
String: URL string.

Example

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

getPresignedObjectUrl(Method method, String bucketName, String objectName, Integer expires, Map reqParams)

public String getPresignedObjectUrl(Method method, String bucketName, String objectName, Integer expires, Map<String,String> reqParams) [Javadoc]

Returns a presigned URL string with given HTTP method, expiry time and custom request params for a specific object in the bucket.

Parameters
| Parameter | Type | Description |
|:---------------|:---------------------|:---------------------------------------|
| method | Method | HTTP method to generate presigned URL. |
| bucketName | String | Name of the bucket. |
| objectName | String | Object name in the bucket. |
| expiry | Integer | Expiry in seconds; defaults to 7 days. |
| reqParams | Map | Request parameters to override. |

Returns
String: URL string.

Example

String url = getPresignedObjectUrl(Method.PUT, "my-bucketname", null, null, null);
System.out.println("my-bucketname can be created by " + url);

isObjectLegalHoldEnabled(String bucketName, String objectName, String versionId)

public boolean isObjectLegalHoldEnabled(String bucketName, String objectName, String versionId) [Javadoc]

Returns true if object legal hold is enabled.

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

Returns
boolean: true if legal hold is enabled.

Example

boolean status = s3Client.isObjectLegalHoldEnabled("my-bucketname", "my-objectname", null);
if (status) {
  System.out.println("Legal hold is on");
else {
  System.out.println("Legal hold is off");
}

presignedGetObject(String bucketName, String objectName)

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

Returns an presigned URL to download the object in the bucket with default expiry time. Default expiry time is 7 days in seconds.

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

Returns
String: URL string to download the object.

Example

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

presignedGetObject(String bucketName, String objectName, Integer expires)

public String presignedGetObject(String bucketName, String objectName, Integer expires) [Javadoc]

Generates a presigned URL for HTTP GET operations. Browsers/Mobile clients may point to this URL to directly download objects even if the bucket is private. This presigned URL can have an associated expiration time in seconds after which it is no longer operational. The default expiry is set to 7 days.

Parameters
| Parameter | Type | Description |
|:---------------|:----------|:----------------------------------------------------|
| bucketName | String | Name of the bucket. |
| objectName | String | Object name in the bucket. |
| expiry | Integer | Expiry in seconds. Default expiry is set to 7 days. |

Returns
String: URL string to download the object.

Example

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

presignedGetObject(String bucketName, String objectName, Integer expires, Map reqParams)

public String presignedGetObject(String bucketName, String objectName, Integer expires, Map<String,String> reqParams) [Javadoc]

Returns an presigned URL to download the object in the bucket with given expiry time with custom request params.

Parameters
| Parameter | Type | Description |
|:---------------|:---------------------|:---------------------------------------|
| bucketName | String | Name of the bucket. |
| objectName | String | Object name in the bucket. |
| expiry | Integer | Expiry in seconds; defaults to 7 days. |
| reqParams | Map | Request parameters to override. |

Returns
String: URL string to download the object.

Example

String url = minioClient.presignedGetObject("my-bucketname", "my-objectname", 60 * 60 * 24, reqParams);
System.out.println("my-bucketname/my-objectname can be downloaded by " + url);

presignedPostPolicy(PostPolicy policy)

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

Allows setting policy conditions to a presigned URL for POST operations. Policies such as bucket name to receive object uploads, key name prefixes, expiry policy may be set. The client receives HTTP status code under key success_action_status, when the file is uploaded successfully. If its value is set to 201, the client notifies with a XML document containing the key where the file was uploaded to.

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

Returns
Map: key/value pairs to construct form-data.

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");

presignedPutObject(String bucketName, String objectName)

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

Returns a presigned URL to upload an object in the bucket with default expiry time. Default expiry time is 7 days in seconds.

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

Returns
String: URL string to upload an object.

Example

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

presignedPutObject(String bucketName, String objectName, Integer expires)

public String presignedPutObject(String bucketName, String objectName, Integer expires) [Javadoc]

Generates a presigned URL for HTTP PUT operations. Browsers/Mobile clients may point to this URL to upload objects directly to a bucket even if it is private. This presigned URL can have an associated expiration time in seconds after which it is no longer operational. The default expiry is set to 7 days.

Parameters
| Parameter | Type | Description |
|:---------------|:----------|:---------------------------------------|
| bucketName | String | Name of the bucket. |
| objectName | String | Object name in the bucket. |
| expiry | Integer | Expiry in seconds; defaults to 7 days. |

Returns
String: URL string to upload an object.

Example

String url = minioClient.presignedPutObject("my-bucketname", "my-objectname", 60 * 60 * 24);
System.out.println("my-bucketname/my-objectname can be uploaded by " + url);

putObject(String bucketName, String objectName, InputStream stream, PutObjectOptions options)

public void putObject(String bucketName, String objectName, InputStream stream, PutObjectOptions options) [Javadoc]

Uploads given stream as object in bucket by using given options.

Parameters
| Parameter | Type | Description |
|:---------------|:---------------------|:-------------------------------|
| bucketName | String | Name of the bucket. |
| objectName | String | Object name in the bucket. |
| stream | InputStream | Stream contains object data. |
| options | PutObjectOptions | Options to be used for upload. |

Example

minioClient.putObject("my-bucketname", "my-objectname", stream, new PutObjectOptions(-1, 5 * MB));

putObject(String bucketName, String objectName, String filename, PutObjectOptions options)

public void putObject(String bucketName, String objectName, String filename, PutObjectOptions options) [Javadoc]

Uploads contents from a file as object in bucket using options.

Parameters
| Parameter | Type | Description |
|:---------------|:---------------------|:-------------------------------|
| bucketName | String | Name of the bucket. |
| objectName | String | Object name in the bucket. |
| fileName | String | File name. |
| options | PutObjectOptions | Options to be used for upload. |

Example

minioClient.putObject("my-bucketname", "my-objectname", "/mnt/photos/island,jpg", new PutObjectOptions(11 * MB, -1));

removeObject(String bucketName, String objectName)

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

Removes an object.

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

Example

minioClient.removeObject("my-bucketname", "my-objectname");

removeObjects(String bucketName, Iterable objectNames)

public Iterable<Result<DeleteError>> removeObjects(String bucketName, Iterable<String> objectNames) [Javadoc]

Removes multiple objects.

Parameters
| Parameter | Type | Description |
|:----------------|:-------------------|:--------------------|
| bucketName | String | Name of the bucket. |
| objectNames | Iterable | List of objects. |

Returns
Iterable<Result<DeleteError>>: an iterator contains errors on object removal.

Example

List<String> myObjectNames = new LinkedList<String>();
objectNames.add("my-objectname1");
objectNames.add("my-objectname2");
objectNames.add("my-objectname3");
Iterable<Result<DeleteError>> results = minioClient.removeObjects("my-bucketname", myObjectNames);
for (Result<DeleteError> result : results) {
  DeleteError error = errorResult.get();
  System.out.println("Error in deleting object " + error.objectName() + "; " + error.message());
}

selectObjectContent(String bucketName, String objectName, String sqlExpression, InputSerialization is, OutputSerialization os, boolean requestProgress, Long scanStartRange, Long scanEndRange, ServerSideEncryption sse)

public SelectResponseStream selectObjectContent(String bucketName, String objectName, String sqlExpression, InputSerialization is, OutputSerialization os, boolean requestProgress, Long scanStartRange, Long scanEndRange, ServerSideEncryption sse) [Javadoc]

Select object content using SQL expression.

Parameters

Parameter Type Description
bucketName String Name of the bucket.
objectName String Object name in the bucket.
sqlExpression String SQL expression.
is InputSerialization Object's input specification.
os OutputSerialization Object's output specification.
requestProgress boolean Flag to request progress information.
scanStartRange Long scan start range of the object.
scanEndRange Long scan end range of the object.
sse ServerSideEncryption Server-side encryptio.n
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("my-bucketname", "my-objectName", sqlExpression, is, os, true, null, null, null);

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(String bucketName, String objectName, String versionId, boolean bypassGovernanceRetention, Retention retention)

public void setObjectLockRetention(String bucketName, String objectName, String versionId, boolean bypassGovernanceRetention, Retention retention) [Javadoc]

Applies object retention lock onto an object.

Parameters
| Parameter | Type | Description |
|:------------------------------|:--------------|:--------------------------------|
| bucketName | String | Name of the bucket. |
| objectName | String | Object name in the bucket. |
| versionId | String | Object version. |
| bypassGovernanceRetention | bool | By pass Governance Retention. |
| config | Retention | Object retention configuration. |

Example

Retention retention = new Retention(RetentionMode.COMPLIANCE, ZonedDateTime.now().plusYears(1));
minioClient.setObjectRetention("my-bucketname", "my-objectname", null, true, retention);

statObject(String bucketName, String objectName)

public ObjectStat statObject(String bucketName, String objectName) [Javadoc]

Gets metadata of an object.

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

Returns
ObjectStat: object metadata.

Example

ObjectStat objectStat = minioClient.statObject("my-bucketname", "my-objectname");

statObject(String bucketName, String objectName, ServerSideEncryption sse)

public ObjectStat statObject(String bucketName, String objectName, ServerSideEncryption sse) [Javadoc]

Returns meta data information of given object in given bucket.

Parameters
| Parameter | Type | Description |
|:---------------|:-------------------------|:-----------------------------------|
| bucketName | String | Name of the bucket. |
| objectName | String | Object name in the bucket. |
| sse | ServerSideEncryption | SSE-C type Server-side encryption. |

Returns
ObjectStat: object metadata.

Example

ObjectStat objectStat = minioClient.statObject("my-bucketname", "my-objectname", sse);

5. Explore Further