public final class MinioClient extends Object
This class implements a simple cloud storage client. This client consists of a useful subset of S3 compatible functionality.
Optionally, users can also provide access/secret keys. If keys are provided, all requests by the client will be signed using AWS Signature Version 4.
For examples on using this library, please see .| Constructor and Description |
|---|
MinioClient(com.squareup.okhttp.HttpUrl url)
Creates Minio client object with given HttpUrl object using anonymous access.
|
MinioClient(com.squareup.okhttp.HttpUrl url,
String accessKey,
String secretKey)
Creates Minio client object with given URL object, access key and secret key.
|
MinioClient(String endpoint)
Creates Minio client object with given endpoint using anonymous access.
|
MinioClient(String endpoint,
int port,
String accessKey,
String secretKey)
Creates Minio client object with given endpoint, port, access key and secret key using secure (HTTPS) connection.
|
MinioClient(String endpoint,
int port,
String accessKey,
String secretKey,
boolean secure)
Creates Minio client object using given endpoint, port, access key, secret key and secure option.
|
MinioClient(String endpoint,
String accessKey,
String secretKey)
Creates Minio client object with given endpoint, access key and secret key.
|
MinioClient(String endpoint,
String accessKey,
String secretKey,
boolean secure)
Creates Minio client object with given endpoint, access key and secret key using secure (HTTPS) connection.
|
MinioClient(URL url)
Creates Minio client object with given URL object using anonymous access.
|
MinioClient(URL url,
String accessKey,
String secretKey)
Creates Minio client object with given URL object, access key and secret key.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
bucketExists(String bucketName)
Checks if given bucket exist and is having read access.
|
PolicyType |
getBucketPolicy(String bucketName,
String objectPrefix)
Get bucket policy at given objectPrefix
|
InputStream |
getObject(String bucketName,
String objectName)
Gets entire object's data as
InputStream in given bucket. |
InputStream |
getObject(String bucketName,
String objectName,
long offset)
Gets object's data starting from given offset as
InputStream in the given bucket. |
InputStream |
getObject(String bucketName,
String objectName,
long offset,
Long length)
Gets object's data of given offset and length as
InputStream in the given bucket. |
void |
getObject(String bucketName,
String objectName,
String fileName)
Gets object's data in the given bucket and stores it to given file name.
|
List<Bucket> |
listBuckets()
Returns all bucket information owned by the current user.
|
Iterable<Result<Upload>> |
listIncompleteUploads(String bucketName)
Lists incomplete uploads of objects in given bucket.
|
Iterable<Result<Upload>> |
listIncompleteUploads(String bucketName,
String prefix)
Lists incomplete uploads of objects in given bucket and prefix.
|
Iterable<Result<Upload>> |
listIncompleteUploads(String bucketName,
String prefix,
boolean recursive)
Lists incomplete uploads of objects in given bucket, prefix and recursive flag.
|
Iterable<Result<Item>> |
listObjects(String bucketName)
Lists object information in given bucket.
|
Iterable<Result<Item>> |
listObjects(String bucketName,
String prefix)
Lists object information in given bucket and prefix.
|
Iterable<Result<Item>> |
listObjects(String bucketName,
String prefix,
boolean recursive)
Lists object information as
Iterable<Result><Item>> in given bucket, prefix and recursive flag. |
void |
makeBucket(String bucketName)
Creates a bucket with default region.
|
void |
makeBucket(String bucketName,
String region)
Creates a bucket with given region.
|
String |
presignedGetObject(String bucketName,
String objectName)
Returns an presigned URL to download the object in the bucket with default expiry time.
|
String |
presignedGetObject(String bucketName,
String objectName,
Integer expires)
Returns an presigned URL to download the object in the bucket with given expiry time.
|
String |
presignedGetObject(String bucketName,
String objectName,
Integer expires,
Map<String,String> reqParams)
Returns an presigned URL to download the object in the bucket with given expiry time with custom request params.
|
Map<String,String> |
presignedPostPolicy(PostPolicy policy)
Returns string map for given
PostPolicy to upload object with various post policy conditions. |
String |
presignedPutObject(String bucketName,
String objectName)
Returns a presigned URL to upload an object in the bucket with default expiry time.
|
String |
presignedPutObject(String bucketName,
String objectName,
Integer expires)
Returns a presigned URL to upload an object in the bucket with given expiry time.
|
void |
putObject(String bucketName,
String objectName,
InputStream stream,
long size,
String contentType)
Uploads data from given stream as object to given bucket.
|
void |
putObject(String bucketName,
String objectName,
String fileName)
Uploads given file as object in given bucket.
|
void |
removeBucket(String bucketName)
Removes a bucket.
|
void |
removeIncompleteUpload(String bucketName,
String objectName)
Removes incomplete multipart upload of given object.
|
void |
removeObject(String bucketName,
String objectName)
Removes an object from a bucket.
|
void |
setAppInfo(String name,
String version)
Sets application's name/version to user agent.
|
void |
setBucketPolicy(String bucketName,
String objectPrefix,
PolicyType policyType)
Set policy on bucket and object prefix.
|
void |
setTimeout(long connectTimeout,
long writeTimeout,
long readTimeout)
Sets HTTP connect, write and read timeouts.
|
ObjectStat |
statObject(String bucketName,
String objectName)
Returns meta data information of given object in given bucket.
|
void |
traceOff()
Disables HTTP call tracing previously enabled.
|
void |
traceOn(OutputStream traceStream)
Enables HTTP call tracing and written to traceStream.
|
public MinioClient(String endpoint) throws InvalidEndpointException, InvalidPortException
MinioClient minioClient = new MinioClient("https://play.minio.io:9000"); endpoint - Request endpoint. Endpoint is an URL, domain name, IPv4 or IPv6 address.
Valid endpoints:
* https://s3.amazonaws.com
* https://s3.amazonaws.com/
* https://play.minio.io:9000
* http://play.minio.io:9010/
* localhost
* localhost.localdomain
* play.minio.io
* 127.0.0.1
* 192.168.1.60
* ::1InvalidEndpointExceptionInvalidPortExceptionMinioClient(URL url),
MinioClient(String endpoint, String accessKey, String secretKey),
MinioClient(URL url, String accessKey, String secretKey),
MinioClient(String endpoint, int port, String accessKey, String secretKey),
MinioClient(String endpoint, String accessKey, String secretKey, boolean secure),
MinioClient(String endpoint, int port, String accessKey, String secretKey, boolean secure)public MinioClient(URL url) throws InvalidEndpointException, InvalidPortException
MinioClient minioClient = new MinioClient(new URL("https://play.minio.io:9000")); url - Endpoint URL object.InvalidEndpointExceptionInvalidPortExceptionMinioClient(String endpoint),
MinioClient(String endpoint, String accessKey, String secretKey),
MinioClient(URL url, String accessKey, String secretKey),
MinioClient(String endpoint, int port, String accessKey, String secretKey),
MinioClient(String endpoint, String accessKey, String secretKey, boolean secure),
MinioClient(String endpoint, int port, String accessKey, String secretKey, boolean secure)public MinioClient(com.squareup.okhttp.HttpUrl url)
throws InvalidEndpointException,
InvalidPortException
MinioClient minioClient = new MinioClient(new HttpUrl.parse("https://play.minio.io:9000")); url - Endpoint HttpUrl object.InvalidEndpointExceptionInvalidPortExceptionMinioClient(String endpoint),
MinioClient(URL url),
MinioClient(String endpoint, String accessKey, String secretKey),
MinioClient(URL url, String accessKey, String secretKey),
MinioClient(String endpoint, int port, String accessKey, String secretKey),
MinioClient(String endpoint, String accessKey, String secretKey, boolean secure),
MinioClient(String endpoint, int port, String accessKey, String secretKey, boolean secure)public MinioClient(String endpoint, String accessKey, String secretKey) throws InvalidEndpointException, InvalidPortException
MinioClient minioClient = new MinioClient("https://play.minio.io:9000",
"YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY"); endpoint - Request endpoint. Endpoint is an URL, domain name, IPv4 or IPv6 address.
Valid endpoints:
* https://s3.amazonaws.com
* https://s3.amazonaws.com/
* https://play.minio.io:9000
* http://play.minio.io:9010/
* localhost
* localhost.localdomain
* play.minio.io
* 127.0.0.1
* 192.168.1.60
* ::1accessKey - Access key to access service in endpoint.secretKey - Secret key to access service in endpoint.InvalidEndpointExceptionInvalidPortExceptionMinioClient(String endpoint),
MinioClient(URL url),
MinioClient(URL url, String accessKey, String secretKey),
MinioClient(String endpoint, int port, String accessKey, String secretKey),
MinioClient(String endpoint, String accessKey, String secretKey, boolean secure),
MinioClient(String endpoint, int port, String accessKey, String secretKey, boolean secure)public MinioClient(URL url, String accessKey, String secretKey) throws InvalidEndpointException, InvalidPortException
MinioClient minioClient = new MinioClient(new URL("https://play.minio.io:9000"),
"YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY"); url - Endpoint URL object.accessKey - Access key to access service in endpoint.secretKey - Secret key to access service in endpoint.InvalidEndpointExceptionInvalidPortExceptionMinioClient(String endpoint),
MinioClient(URL url),
MinioClient(String endpoint, String accessKey, String secretKey),
MinioClient(String endpoint, int port, String accessKey, String secretKey),
MinioClient(String endpoint, String accessKey, String secretKey, boolean secure),
MinioClient(String endpoint, int port, String accessKey, String secretKey, boolean secure)public MinioClient(com.squareup.okhttp.HttpUrl url,
String accessKey,
String secretKey)
throws InvalidEndpointException,
InvalidPortException
MinioClient minioClient = new MinioClient(HttpUrl.parse("https://play.minio.io:9000"),
"YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY"); url - Endpoint HttpUrl object.accessKey - Access key to access service in endpoint.secretKey - Secret key to access service in endpoint.InvalidEndpointExceptionInvalidPortExceptionMinioClient(String endpoint),
MinioClient(URL url),
MinioClient(String endpoint, String accessKey, String secretKey),
MinioClient(URL url, String accessKey, String secretKey),
MinioClient(String endpoint, int port, String accessKey, String secretKey),
MinioClient(String endpoint, String accessKey, String secretKey, boolean secure),
MinioClient(String endpoint, int port, String accessKey, String secretKey, boolean secure)public MinioClient(String endpoint, int port, String accessKey, String secretKey) throws InvalidEndpointException, InvalidPortException
MinioClient minioClient =
new MinioClient("play.minio.io", 9000, "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY");
endpoint - Request endpoint. Endpoint is an URL, domain name, IPv4 or IPv6 address.
Valid endpoints:
* https://s3.amazonaws.com
* https://s3.amazonaws.com/
* https://play.minio.io:9000
* http://play.minio.io:9010/
* localhost
* localhost.localdomain
* play.minio.io
* 127.0.0.1
* 192.168.1.60
* ::1port - Valid port. It should be in between 1 and 65535. Unused if endpoint is an URL.accessKey - Access key to access service in endpoint.secretKey - Secret key to access service in endpoint.InvalidEndpointExceptionInvalidPortExceptionMinioClient(String endpoint),
MinioClient(URL url),
MinioClient(String endpoint, String accessKey, String secretKey),
MinioClient(URL url, String accessKey, String secretKey),
MinioClient(String endpoint, String accessKey, String secretKey, boolean secure),
MinioClient(String endpoint, int port, String accessKey, String secretKey, boolean secure)public MinioClient(String endpoint, String accessKey, String secretKey, boolean secure) throws InvalidEndpointException, InvalidPortException
MinioClient minioClient =
new MinioClient("play.minio.io:9000", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true);
endpoint - Request endpoint. Endpoint is an URL, domain name, IPv4 or IPv6 address.
Valid endpoints:
* https://s3.amazonaws.com
* https://s3.amazonaws.com/
* https://play.minio.io:9000
* http://play.minio.io:9010/
* localhost
* localhost.localdomain
* play.minio.io
* 127.0.0.1
* 192.168.1.60
* ::1accessKey - Access key to access service in endpoint.secretKey - Secret key to access service in endpoint.secure - If true, access endpoint using HTTPS else access it using HTTP.InvalidEndpointExceptionInvalidPortExceptionMinioClient(String endpoint),
MinioClient(URL url),
MinioClient(String endpoint, String accessKey, String secretKey),
MinioClient(URL url, String accessKey, String secretKey),
MinioClient(String endpoint, int port, String accessKey, String secretKey),
MinioClient(String endpoint, int port, String accessKey, String secretKey, boolean secure)public MinioClient(String endpoint, int port, String accessKey, String secretKey, boolean secure) throws InvalidEndpointException, InvalidPortException
MinioClient minioClient =
new MinioClient("play.minio.io", 9000, "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", false);
endpoint - Request endpoint. Endpoint is an URL, domain name, IPv4 or IPv6 address.
Valid endpoints:
* https://s3.amazonaws.com
* https://s3.amazonaws.com/
* https://play.minio.io:9000
* http://play.minio.io:9010/
* localhost
* localhost.localdomain
* play.minio.io
* 127.0.0.1
* 192.168.1.60
* ::1port - Valid port. It should be in between 1 and 65535. Unused if endpoint is an URL.accessKey - Access key to access service in endpoint.secretKey - Secret key to access service in endpoint.secure - If true, access endpoint using HTTPS else access it using HTTP.InvalidEndpointExceptionInvalidPortExceptionMinioClient(String endpoint),
MinioClient(URL url),
MinioClient(String endpoint, String accessKey, String secretKey),
MinioClient(URL url, String accessKey, String secretKey),
MinioClient(String endpoint, int port, String accessKey, String secretKey),
MinioClient(String endpoint, String accessKey, String secretKey, boolean secure)public void setTimeout(long connectTimeout,
long writeTimeout,
long readTimeout)
minioClient.setTimeout(TimeUnit.SECONDS.toMillis(10), TimeUnit.SECONDS.toMillis(10),
TimeUnit.SECONDS.toMillis(30)); connectTimeout - HTTP connect timeout in milliseconds.writeTimeout - HTTP write timeout in milliseconds.readTimeout - HTTP read timeout in milliseconds.public void setAppInfo(String name, String version)
name - Your application name.version - Your application version.public ObjectStat statObject(String bucketName, String objectName) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, InvalidKeyException, NoResponseException, org.xmlpull.v1.XmlPullParserException, ErrorResponseException, InternalException
ObjectStat objectStat = minioClient.statObject("my-bucketname", "my-objectname");
System.out.println(objectStat); bucketName - Bucket name.objectName - Object name in the bucket.InvalidBucketNameException - upon invalid bucket name is givenNoResponseException - upon no response from serverIOException - upon connection errororg.xmlpull.v1.XmlPullParserException - upon parsing response xmlErrorResponseException - upon unsuccessful executionInternalException - upon internal library errorNoSuchAlgorithmExceptionInsufficientDataExceptionInvalidKeyExceptionObjectStatpublic InputStream getObject(String bucketName, String objectName) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, InvalidKeyException, NoResponseException, org.xmlpull.v1.XmlPullParserException, ErrorResponseException, InternalException, InvalidArgumentException
InputStream in given bucket. The InputStream must be closed
after use else the connection will remain open.
Example:
InputStream stream = minioClient.getObject("my-bucketname", "my-objectname");
byte[] buf = new byte[16384];
int bytesRead;
while ((bytesRead = stream.read(buf, 0, buf.length)) >= 0) {
System.out.println(new String(buf, 0, bytesRead));
}
stream.close(); bucketName - Bucket name.objectName - Object name in the bucket.InputStream containing the object data.InvalidBucketNameException - upon invalid bucket name is givenNoResponseException - upon no response from serverIOException - upon connection errororg.xmlpull.v1.XmlPullParserException - upon parsing response xmlErrorResponseException - upon unsuccessful executionInternalException - upon internal library errorNoSuchAlgorithmExceptionInsufficientDataExceptionInvalidKeyExceptionInvalidArgumentExceptionpublic InputStream getObject(String bucketName, String objectName, long offset) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, InvalidKeyException, NoResponseException, org.xmlpull.v1.XmlPullParserException, ErrorResponseException, InternalException, InvalidArgumentException
InputStream in the given bucket. The InputStream must be
closed after use else the connection will remain open.
Example: InputStream stream = minioClient.getObject("my-bucketname", "my-objectname", 1024L);
byte[] buf = new byte[16384];
int bytesRead;
while ((bytesRead = stream.read(buf, 0, buf.length)) >= 0) {
System.out.println(new String(buf, 0, bytesRead));
}
stream.close(); bucketName - Bucket name.objectName - Object name in the bucket.offset - Offset to read at.InputStream containing the object's data.InvalidBucketNameException - upon invalid bucket name is givenNoResponseException - upon no response from serverIOException - upon connection errororg.xmlpull.v1.XmlPullParserException - upon parsing response xmlErrorResponseException - upon unsuccessful executionInternalException - upon internal library errorNoSuchAlgorithmExceptionInsufficientDataExceptionInvalidKeyExceptionInvalidArgumentExceptionpublic InputStream getObject(String bucketName, String objectName, long offset, Long length) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, InvalidKeyException, NoResponseException, org.xmlpull.v1.XmlPullParserException, ErrorResponseException, InternalException, InvalidArgumentException
InputStream in the given bucket. The InputStream must be
closed after use else the connection will remain open.
Example: InputStream stream = minioClient.getObject("my-bucketname", "my-objectname", 1024L, 4096L);
byte[] buf = new byte[16384];
int bytesRead;
while ((bytesRead = stream.read(buf, 0, buf.length)) >= 0) {
System.out.println(new String(buf, 0, bytesRead));
}
stream.close(); bucketName - Bucket name.objectName - Object name in the bucket.offset - Offset to read at.length - Length to read.InputStream containing the object's data.InvalidBucketNameException - upon invalid bucket name is givenNoResponseException - upon no response from serverIOException - upon connection errororg.xmlpull.v1.XmlPullParserException - upon parsing response xmlErrorResponseException - upon unsuccessful executionInternalException - upon internal library errorNoSuchAlgorithmExceptionInsufficientDataExceptionInvalidKeyExceptionInvalidArgumentExceptionpublic void getObject(String bucketName, String objectName, String fileName) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, InvalidKeyException, NoResponseException, org.xmlpull.v1.XmlPullParserException, ErrorResponseException, InternalException, InvalidArgumentException
minioClient.getObject("my-bucketname", "my-objectname", "photo.jpg"); bucketName - Bucket name.objectName - Object name in the bucket.fileName - file name.InvalidBucketNameException - upon invalid bucket name is givenNoResponseException - upon no response from serverIOException - upon connection errororg.xmlpull.v1.XmlPullParserException - upon parsing response xmlErrorResponseException - upon unsuccessful executionInternalException - upon internal library errorNoSuchAlgorithmExceptionInsufficientDataExceptionInvalidKeyExceptionInvalidArgumentExceptionpublic String presignedGetObject(String bucketName, String objectName, Integer expires, Map<String,String> reqParams) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, InvalidKeyException, NoResponseException, org.xmlpull.v1.XmlPullParserException, ErrorResponseException, InternalException, InvalidExpiresRangeException
String url = minioClient.presignedGetObject("my-bucketname", "my-objectname", 60 * 60 * 24, reqParams);
System.out.println(url); bucketName - Bucket name.objectName - Object name in the bucket.expires - Expiration time in seconds of presigned URL.reqParams - Override values for set of response headers. Currently supported request parameters are
[response-expires, response-content-type, response-cache-control, response-content-disposition]InvalidBucketNameException - upon an invalid bucket nameInvalidKeyException - upon an invalid access key or secret keyIOException - upon signature calculation failureNoSuchAlgorithmException - upon requested algorithm was not found during signature calculationInvalidExpiresRangeException - upon input expires is out of rangeInsufficientDataExceptionNoResponseExceptionorg.xmlpull.v1.XmlPullParserExceptionErrorResponseExceptionInternalExceptionpublic String presignedGetObject(String bucketName, String objectName, Integer expires) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, InvalidKeyException, NoResponseException, org.xmlpull.v1.XmlPullParserException, ErrorResponseException, InternalException, InvalidExpiresRangeException
String url = minioClient.presignedGetObject("my-bucketname", "my-objectname", 60 * 60 * 24);
System.out.println(url); bucketName - Bucket name.objectName - Object name in the bucket.expires - Expiration time in seconds of presigned URL.InvalidBucketNameException - upon an invalid bucket nameInvalidKeyException - upon an invalid access key or secret keyIOException - upon signature calculation failureNoSuchAlgorithmException - upon requested algorithm was not found during signature calculationInvalidExpiresRangeException - upon input expires is out of rangeInsufficientDataExceptionNoResponseExceptionorg.xmlpull.v1.XmlPullParserExceptionErrorResponseExceptionInternalExceptionpublic String presignedGetObject(String bucketName, String objectName) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, InvalidKeyException, NoResponseException, org.xmlpull.v1.XmlPullParserException, ErrorResponseException, InternalException, InvalidExpiresRangeException
String url = minioClient.presignedGetObject("my-bucketname", "my-objectname");
System.out.println(url); bucketName - Bucket name.objectName - Object name in the bucket.IOException - upon connection errorNoSuchAlgorithmException - upon requested algorithm was not found during signature calculationInvalidExpiresRangeException - upon input expires is out of rangeInvalidBucketNameExceptionInsufficientDataExceptionInvalidKeyExceptionNoResponseExceptionorg.xmlpull.v1.XmlPullParserExceptionErrorResponseExceptionInternalExceptionpublic String presignedPutObject(String bucketName, String objectName, Integer expires) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, InvalidKeyException, NoResponseException, org.xmlpull.v1.XmlPullParserException, ErrorResponseException, InternalException, InvalidExpiresRangeException
String url = minioClient.presignedPutObject("my-bucketname", "my-objectname", 60 * 60 * 24);
System.out.println(url); bucketName - Bucket nameobjectName - Object name in the bucketexpires - Expiration time in seconds to presigned URL.InvalidBucketNameException - upon an invalid bucket nameInvalidKeyException - upon an invalid access key or secret keyIOException - upon signature calculation failureNoSuchAlgorithmException - upon requested algorithm was not found during signature calculationInvalidExpiresRangeException - upon input expires is out of rangeInsufficientDataExceptionNoResponseExceptionorg.xmlpull.v1.XmlPullParserExceptionErrorResponseExceptionInternalExceptionpublic String presignedPutObject(String bucketName, String objectName) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, InvalidKeyException, NoResponseException, org.xmlpull.v1.XmlPullParserException, ErrorResponseException, InternalException, InvalidExpiresRangeException
String url = minioClient.presignedPutObject("my-bucketname", "my-objectname");
System.out.println(url); bucketName - Bucket name.objectName - Object name in the bucket.IOException - upon connection errorNoSuchAlgorithmException - upon requested algorithm was not found during signature calculationInvalidExpiresRangeException - upon input expires is out of rangeInvalidBucketNameExceptionInsufficientDataExceptionInvalidKeyExceptionNoResponseExceptionorg.xmlpull.v1.XmlPullParserExceptionErrorResponseExceptionInternalExceptionpublic Map<String,String> presignedPostPolicy(PostPolicy policy) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, InvalidKeyException, NoResponseException, org.xmlpull.v1.XmlPullParserException, ErrorResponseException, InternalException
PostPolicy to upload object with various post policy conditions.
Example: // Create new PostPolicy object for 'my-bucketname', 'my-objectname' and 7 days expire time from now.
PostPolicy policy = new PostPolicy("my-bucketname", "my-objectname", DateTime.now().plusDays(7));
// 'my-objectname' should be 'image/png' content type
policy.setContentType("image/png");
Map<String,String> formData = minioClient.presignedPostPolicy(policy);
// Print a curl command that can be executable with the file /tmp/userpic.png and the file will be uploaded.
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.minio.io:9000/my-bucketname"); policy - Post policy of an object.InvalidBucketNameExceptionNoSuchAlgorithmExceptionInsufficientDataExceptionIOExceptionInvalidKeyExceptionNoResponseExceptionorg.xmlpull.v1.XmlPullParserExceptionErrorResponseExceptionInternalExceptionPostPolicypublic void removeObject(String bucketName, String objectName) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, InvalidKeyException, NoResponseException, org.xmlpull.v1.XmlPullParserException, ErrorResponseException, InternalException
minioClient.removeObject("my-bucketname", "my-objectname"); bucketName - Bucket name.objectName - Object name in the bucket.InvalidBucketNameException - upon invalid bucket name is givenNoResponseException - upon no response from serverIOException - upon connection errororg.xmlpull.v1.XmlPullParserException - upon parsing response xmlErrorResponseException - upon unsuccessful executionInternalException - upon internal library errorNoSuchAlgorithmExceptionInsufficientDataExceptionInvalidKeyExceptionpublic Iterable<Result<Item>> listObjects(String bucketName) throws org.xmlpull.v1.XmlPullParserException
bucketName - Bucket name.org.xmlpull.v1.XmlPullParserExceptionpublic Iterable<Result<Item>> listObjects(String bucketName, String prefix) throws org.xmlpull.v1.XmlPullParserException
bucketName - Bucket name.prefix - Prefix string. List objects whose name starts with `prefix`.org.xmlpull.v1.XmlPullParserExceptionpublic Iterable<Result<Item>> listObjects(String bucketName, String prefix, boolean recursive)
Iterable<Result><Item>> in given bucket, prefix and recursive flag.
Example: Iterable<Result<Item>> myObjects = minioClient.listObjects("my-bucketname");
for (Result<Item> result : myObjects) {
Item item = result.get();
System.out.println(item.lastModified() + ", " + item.size() + ", " + item.objectName());
} bucketName - Bucket name.prefix - Prefix string. List objects whose name starts with `prefix`.recursive - when false, emulates a directory structure where each listing returned is either a full object
or part of the object's key up to the first '/'. All objects wit the same prefix up to the first
'/' will be merged into one entry.listObjects(String bucketName),
listObjects(String bucketName, String prefix)public List<Bucket> listBuckets() throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, InvalidKeyException, NoResponseException, org.xmlpull.v1.XmlPullParserException, ErrorResponseException, InternalException
List<Bucket> bucketList = minioClient.listBuckets();
for (Bucket bucket : bucketList) {
System.out.println(bucket.creationDate() + ", " + bucket.name());
} NoResponseException - upon no response from serverIOException - upon connection errororg.xmlpull.v1.XmlPullParserException - upon parsing response xmlErrorResponseException - upon unsuccessful executionInternalException - upon internal library errorInvalidBucketNameExceptionNoSuchAlgorithmExceptionInsufficientDataExceptionInvalidKeyExceptionpublic boolean bucketExists(String bucketName) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, InvalidKeyException, NoResponseException, org.xmlpull.v1.XmlPullParserException, ErrorResponseException, InternalException
boolean found = minioClient.bucketExists("my-bucketname");
if (found) {
System.out.println("my-bucketname exists");
} else {
System.out.println("my-bucketname does not exist");
} bucketName - Bucket name.InvalidBucketNameException - upon invalid bucket name is givenNoResponseException - upon no response from serverIOException - upon connection errororg.xmlpull.v1.XmlPullParserException - upon parsing response xmlErrorResponseException - upon unsuccessful executionInternalException - upon internal library errorNoSuchAlgorithmExceptionInsufficientDataExceptionInvalidKeyExceptionpublic void makeBucket(String bucketName) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, InvalidKeyException, NoResponseException, org.xmlpull.v1.XmlPullParserException, ErrorResponseException, InternalException
bucketName - Bucket name.InvalidBucketNameException - upon invalid bucket name is givenNoResponseException - upon no response from serverIOException - upon connection errororg.xmlpull.v1.XmlPullParserException - upon parsing response xmlErrorResponseException - upon unsuccessful executionInternalException - upon internal library errorNoSuchAlgorithmExceptionInsufficientDataExceptionInvalidKeyExceptionpublic void makeBucket(String bucketName, String region) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, InvalidKeyException, NoResponseException, org.xmlpull.v1.XmlPullParserException, ErrorResponseException, InternalException
minioClient.makeBucket("my-bucketname");
System.out.println("my-bucketname is created successfully"); bucketName - Bucket name.region - region in which the bucket will be created.InvalidBucketNameException - upon invalid bucket name is givenNoResponseException - upon no response from serverIOException - upon connection errororg.xmlpull.v1.XmlPullParserException - upon parsing response xmlErrorResponseException - upon unsuccessful executionInternalException - upon internal library errorNoSuchAlgorithmExceptionInsufficientDataExceptionInvalidKeyExceptionpublic void removeBucket(String bucketName) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, InvalidKeyException, NoResponseException, org.xmlpull.v1.XmlPullParserException, ErrorResponseException, InternalException
NOTE: - All objects (including all object versions and delete markers) in the bucket must be deleted prior, this API will not recursively delete objects
Example: minioClient.removeBucket("my-bucketname");
System.out.println("my-bucketname is removed successfully"); bucketName - Bucket name.InvalidBucketNameException - upon invalid bucket name is givenNoResponseException - upon no response from serverIOException - upon connection errororg.xmlpull.v1.XmlPullParserException - upon parsing response xmlErrorResponseException - upon unsuccessful executionInternalException - upon internal library errorNoSuchAlgorithmExceptionInsufficientDataExceptionInvalidKeyExceptionpublic void putObject(String bucketName, String objectName, String fileName) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, InvalidKeyException, NoResponseException, org.xmlpull.v1.XmlPullParserException, ErrorResponseException, InternalException, InvalidArgumentException, InsufficientDataException
If the object is larger than 5MB, the client will automatically use a multipart session.
If the session fails, the user may attempt to re-upload the object by attempting to create the exact same object again. The client will examine all parts of any current upload session and attempt to reuse the session automatically. If a mismatch is discovered, the upload will fail before uploading any more data. Otherwise, it will resume uploading where the session left off.
If the multipart session fails, the user is responsible for resuming or removing the session.
bucketName - Bucket name.objectName - Object name to create in the bucket.fileName - File name to upload.InvalidBucketNameException - upon invalid bucket name is givenNoResponseException - upon no response from serverIOException - upon connection errororg.xmlpull.v1.XmlPullParserException - upon parsing response xmlErrorResponseException - upon unsuccessful executionInternalException - upon internal library errorNoSuchAlgorithmExceptionInsufficientDataExceptionInvalidKeyExceptionInvalidArgumentExceptionpublic void putObject(String bucketName, String objectName, InputStream stream, long size, String contentType) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, InvalidKeyException, NoResponseException, org.xmlpull.v1.XmlPullParserException, ErrorResponseException, InternalException, InvalidArgumentException, InsufficientDataException
If the object is larger than 5MB, the client will automatically use a multipart session.
If the session fails, the user may attempt to re-upload the object by attempting to create the exact same object again. The client will examine all parts of any current upload session and attempt to reuse the session automatically. If a mismatch is discovered, the upload will fail before uploading any more data. Otherwise, it will resume uploading where the session left off.
If the multipart session fails, the user is responsible for resuming or removing the session.
Example: StringBuilder builder = new StringBuilder();
for (int i = 0; i < 1000; i++) {
builder.append("Sphinx of black quartz, judge my vow: Used by Adobe InDesign to display font samples. ");
builder.append("(29 letters)\n");
builder.append("Jackdaws love my big sphinx of quartz: Similarly, used by Windows XP for some fonts. ");
builder.append("(31 letters)\n");
builder.append("Pack my box with five dozen liquor jugs: According to Wikipedia, this one is used on ");
builder.append("NASAs Space Shuttle. (32 letters)\n");
builder.append("The quick onyx goblin jumps over the lazy dwarf: Flavor text from an Unhinged Magic Card. ");
builder.append("(39 letters)\n");
builder.append("How razorback-jumping frogs can level six piqued gymnasts!: Not going to win any brevity ");
builder.append("awards at 49 letters long, but old-time Mac users may recognize it.\n");
builder.append("Cozy lummox gives smart squid who asks for job pen: A 41-letter tester sentence for Mac ");
builder.append("computers after System 7.\n");
builder.append("A few others we like: Amazingly few discotheques provide jukeboxes; Now fax quiz Jack! my ");
builder.append("brave ghost pled; Watch Jeopardy!, Alex Trebeks fun TV quiz game.\n");
builder.append("---\n");
}
ByteArrayInputStream bais = new ByteArrayInputStream(builder.toString().getBytes("UTF-8"));
// create object
minioClient.putObject("my-bucketname", "my-objectname", bais, bais.available(), "application/octet-stream");
bais.close();
System.out.println("my-bucketname is uploaded successfully"); bucketName - Bucket name.objectName - Object name to create in the bucket.stream - stream to upload.size - Size of all the data that will be uploaded.contentType - Content type of the stream.InvalidBucketNameException - upon invalid bucket name is givenNoResponseException - upon no response from serverIOException - upon connection errororg.xmlpull.v1.XmlPullParserException - upon parsing response xmlErrorResponseException - upon unsuccessful executionInternalException - upon internal library errorNoSuchAlgorithmExceptionInsufficientDataExceptionInvalidKeyExceptionInvalidArgumentExceptionputObject(String bucketName, String objectName, String fileName)public PolicyType getBucketPolicy(String bucketName, String objectPrefix) throws InvalidBucketNameException, InvalidObjectPrefixException, NoSuchAlgorithmException, InsufficientDataException, IOException, InvalidKeyException, NoResponseException, org.xmlpull.v1.XmlPullParserException, ErrorResponseException, InternalException
bucketName - Bucket name.objectPrefix - name of the object prefix
Example: String policy = minioClient.getBucketPolicy("my-bucketname", "my-objectname");
System.out.println(policy); InvalidBucketNameExceptionInvalidObjectPrefixExceptionNoSuchAlgorithmExceptionInsufficientDataExceptionIOExceptionInvalidKeyExceptionNoResponseExceptionorg.xmlpull.v1.XmlPullParserExceptionErrorResponseExceptionInternalExceptionpublic void setBucketPolicy(String bucketName, String objectPrefix, PolicyType policyType) throws InvalidBucketNameException, InvalidObjectPrefixException, NoSuchAlgorithmException, InsufficientDataException, IOException, InvalidKeyException, NoResponseException, org.xmlpull.v1.XmlPullParserException, ErrorResponseException, InternalException
bucketName - Bucket name.objectPrefix - Name of the object prefix.policyType - Enum of PolicyType.
Example: setBucketPolicy("my-bucketname", "my-objectname", BucketPolicy.ReadOnly); InvalidBucketNameExceptionInvalidObjectPrefixExceptionNoSuchAlgorithmExceptionInsufficientDataExceptionIOExceptionInvalidKeyExceptionNoResponseExceptionorg.xmlpull.v1.XmlPullParserExceptionErrorResponseExceptionInternalExceptionpublic Iterable<Result<Upload>> listIncompleteUploads(String bucketName) throws org.xmlpull.v1.XmlPullParserException
bucketName - Bucket name.org.xmlpull.v1.XmlPullParserExceptionlistIncompleteUploads(String, String, boolean)public Iterable<Result<Upload>> listIncompleteUploads(String bucketName, String prefix) throws org.xmlpull.v1.XmlPullParserException
bucketName - Bucket name.prefix - filters the list of uploads to include only those that start with prefix.org.xmlpull.v1.XmlPullParserExceptionlistIncompleteUploads(String, String, boolean)public Iterable<Result<Upload>> listIncompleteUploads(String bucketName, String prefix, boolean recursive)
Iterable<Result<Upload>> myObjects = minioClient.listIncompleteUploads("my-bucketname");
for (Result<Upload> result : myObjects) {
Upload upload = result.get();
System.out.println(upload.uploadId() + ", " + upload.objectName());
} bucketName - Bucket name.prefix - Prefix string. List objects whose name starts with `prefix`.recursive - when false, emulates a directory structure where each listing returned is either a full object
or part of the object's key up to the first '/'. All uploads with the same prefix up to the first
'/' will be merged into one entry.listIncompleteUploads(String bucketName),
listIncompleteUploads(String bucketName, String prefix)public void removeIncompleteUpload(String bucketName, String objectName) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, InvalidKeyException, NoResponseException, org.xmlpull.v1.XmlPullParserException, ErrorResponseException, InternalException
minioClient.removeIncompleteUpload("my-bucketname", "my-objectname");
System.out.println("successfully removed all incomplete upload session of my-bucketname/my-objectname"); bucketName - Bucket name.objectName - Object name in the bucket.InvalidBucketNameException - upon invalid bucket name is givenNoResponseException - upon no response from serverIOException - upon connection errororg.xmlpull.v1.XmlPullParserException - upon parsing response xmlErrorResponseException - upon unsuccessful executionInternalException - upon internal library errorNoSuchAlgorithmExceptionInsufficientDataExceptionInvalidKeyExceptionpublic void traceOn(OutputStream traceStream)
traceStream - OutputStream for writing HTTP call tracing.traceOff()public void traceOff()
throws IOException
IOExceptiontraceOn(java.io.OutputStream)