MinioClient minioClient = new MinioClient("https://play.minio.io:9000", "Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
MinioClient s3Client = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY");
Bucket operations | Object operations | Presigned operations | Bucket Policy Operations |
---|---|---|---|
makeBucket |
getObject |
presignedGetObject |
getBucketPolicy |
listBuckets |
putObject |
presignedPutObject |
setBucketPolicy |
bucketExists |
copyObject |
presignedPostPolicy |
|
removeBucket |
statObject |
||
listObjects |
removeObject |
||
listIncompleteUploads |
removeIncompleteUpload |
public MinioClient(String endpoint) throws NullPointerException, InvalidEndpointException, InvalidPortException |
Creates Minio client object with given endpoint using anonymous access. |
View Javadoc |
public MinioClient(URL url) throws NullPointerException, InvalidEndpointException, InvalidPortException |
Creates Minio client object with given url using anonymous access. |
View Javadoc |
public MinioClient(com.squareup.okhttp.HttpUrl url) throws NullPointerException, InvalidEndpointException, InvalidPortException |
Creates Minio client object with given HttpUrl object using anonymous access. |
View Javadoc |
public MinioClient(String endpoint, String accessKey, String secretKey) throws NullPointerException, InvalidEndpointException, InvalidPortException |
Creates Minio client object with given endpoint, access key and secret key. |
View Javadoc |
public MinioClient(String endpoint, int port, String accessKey, String secretKey) throws NullPointerException, InvalidEndpointException, InvalidPortException |
Creates Minio client object with given endpoint, port, access key and secret key using secure (HTTPS) connection. |
View Javadoc |
public MinioClient(String endpoint, String accessKey, String secretKey, boolean secure) throws NullPointerException, InvalidEndpointException, InvalidPortException |
Creates Minio client object with given endpoint, access key and secret key using secure (HTTPS) connection. |
View Javadoc |
public MinioClient(String endpoint, int port, String accessKey, String secretKey, boolean secure) throws NullPointerException, InvalidEndpointException, InvalidPortException |
Creates Minio client object using given endpoint, port, access key, secret key and secure option. |
View Javadoc |
public MinioClient(com.squareup.okhttp.HttpUrl url, String accessKey, String secretKey) throws NullPointerException, InvalidEndpointException, InvalidPortException |
Creates Minio client object with given URL object, access key and secret key. |
View Javadoc |
public MinioClient(URL url, String accessKey, String secretKey) throws NullPointerException, InvalidEndpointException, InvalidPortException |
Creates Minio client object with given URL object, access key and secret key. |
View Javadoc |
Parameters
Param | Type | Description |
---|---|---|
endpoint |
string | endPoint is an URL, domain name, IPv4 address or IPv6 address.Valid endpoints are listed below: |
https://s3.amazonaws.com | ||
https://play.minio.io:9000 | ||
localhost | ||
play.minio.io | ||
port |
int | TCP/IP port number. This input is optional. Default value set to 80 for HTTP and 443 for HTTPs. |
accessKey |
string | accessKey is like user-id that uniquely identifies your account. |
secretKey |
string | secretKey is the password to your account. |
secure |
boolean | If set to true, https is used instead of http. Default is https if not set. |
url |
URL | Endpoint URL object. |
url |
HttpURL | Endpoint HttpUrl object. |
Example
// 1. public MinioClient(String endpoint)
MinioClient minioClient = new MinioClient("https://play.minio.io:9000");
// 2. public MinioClient(URL url)
MinioClient minioClient = new MinioClient(new URL("https://play.minio.io:9000"));
// 3. public MinioClient(com.squareup.okhttp.HttpUrl url)
MinioClient minioClient = new MinioClient(new HttpUrl.parse("https://play.minio.io:9000"));
// 4. public MinioClient(String endpoint, String accessKey, String secretKey)
MinioClient minioClient = new MinioClient("https://play.minio.io:9000", "Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
// 5. public MinioClient(String endpoint, int port, String accessKey, String secretKey)
MinioClient minioClient = new MinioClient("https://play.minio.io", 9000, "Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
// 6. public MinioClient(String endpoint, String accessKey, String secretKey, boolean insecure)
MinioClient minioClient = new MinioClient("https://play.minio.io:9000", "Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG", true);
// 7. public MinioClient(String endpoint, int port, String accessKey, String secretKey, boolean insecure)
MinioClient minioClient = new MinioClient("https://play.minio.io", 9000, "Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG", true);
// 8. public MinioClient(com.squareup.okhttp.HttpUrl url, String accessKey, String secretKey)
MinioClient minioClient = new MinioClient(new URL("https://play.minio.io:9000"), "Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
// 9. public MinioClient(URL url, String accessKey, String secretKey)
MinioClient minioClient = new MinioClient(HttpUrl.parse("https://play.minio.io:9000"), "Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
// 1. public MinioClient(String endpoint)
MinioClient s3Client = new MinioClient("https://s3.amazonaws.com");
// 2. public MinioClient(URL url)
MinioClient minioClient = new MinioClient(new URL("https://s3.amazonaws.com"));
// 3. public MinioClient(com.squareup.okhttp.HttpUrl url)
MinioClient s3Client = new MinioClient(new HttpUrl.parse("https://s3.amazonaws.com"));
// 4. public MinioClient(String endpoint, String accessKey, String secretKey)
MinioClient s3Client = new MinioClient("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY");
// 5. public MinioClient(String endpoint, int port, String accessKey, String secretKey)
MinioClient s3Client = new MinioClient("s3.amazonaws.com", 80, "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY");
// 6. public MinioClient(String endpoint, String accessKey, String secretKey, boolean insecure)
MinioClient s3Client = new MinioClient("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", false);
// 7. public MinioClient(String endpoint, int port, String accessKey, String secretKey, boolean insecure)
MinioClient s3Client = new MinioClient("s3.amazonaws.com", 80, "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY",false);
// 8. public MinioClient(com.squareup.okhttp.HttpUrl url, String accessKey, String secretKey)
MinioClient s3Client = new MinioClient(new URL("s3.amazonaws.com"), "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY");
// 9. public MinioClient(URL url, String accessKey, String secretKey)
MinioClient s3Client = new MinioClient(HttpUrl.parse("s3.amazonaws.com"), "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY");
public void makeBucket(String bucketName)
Creates a new bucket.
Parameters
Param | Type | Description |
---|---|---|
bucketName |
String | Name of the bucket. |
Return Type | Exceptions |
---|---|
None |
Listed Exceptions: |
InvalidBucketNameException : upon invalid bucket name. |
|
NoResponseException : upon no response from server. |
|
IOException : upon connection error. |
|
org.xmlpull.v1.XmlPullParserException : upon parsing response XML. |
|
ErrorResponseException : upon unsuccessful execution. |
|
InternalException : upon internal library error. |
Example
try {
// Create bucket if it doesn't exist.
boolean found = minioClient.bucketExists("mybucket");
if (found) {
System.out.println("mybucket already exists");
} else {
// Create bucket 'my-bucketname'.
minioClient.makeBucket("mybucket");
System.out.println("mybucket is created successfully");
}
} catch (MinioException e) {
System.out.println("Error occurred: " + e);
}
public List<Bucket> listBuckets()
Lists all buckets.
Return Type | Exceptions |
---|---|
List Bucket : List of bucket type. |
Listed Exceptions: |
NoResponseException : upon no response from server. |
|
IOException : upon connection error. |
|
org.xmlpull.v1.XmlPullParserException : upon parsing response XML. |
|
ErrorResponseException : upon unsuccessful execution. |
|
InternalException : upon internal library error. |
Example
try {
// List buckets that have read access.
List<Bucket> bucketList = minioClient.listBuckets();
for (Bucket bucket : bucketList) {
System.out.println(bucket.creationDate() + ", " + bucket.name());
}
} catch (MinioException e) {
System.out.println("Error occurred: " + e);
}
public boolean bucketExists(String bucketName)
Checks if a bucket exists.
Parameters
Param | Type | Description |
---|---|---|
bucketName |
String | Name of the bucket. |
Return Type | Exceptions |
---|---|
boolean : true if the bucket exists |
Listed Exceptions: |
InvalidBucketNameException : upon invalid bucket name. |
|
NoResponseException : upon no response from server. |
|
IOException : upon connection error. |
|
org.xmlpull.v1.XmlPullParserException : upon parsing response XML. |
|
ErrorResponseException : upon unsuccessful execution. |
|
InternalException : upon internal library error. |
Example
try {
// 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");
}
} catch (MinioException e) {
System.out.println("Error occurred: " + e);
}
public void removeBucket(String bucketName)
Removes a bucket.
NOTE: - removeBucket does not delete the objects inside the bucket. The objects need to be deleted using the removeObject API.
Parameters
Param | Type | Description |
---|---|---|
bucketName |
String | Name of the bucket. |
Return Type | Exceptions |
---|---|
None | Listed Exceptions: |
InvalidBucketNameException : upon invalid bucket name. |
|
NoResponseException : upon no response from server. |
|
IOException : upon connection error. |
|
org.xmlpull.v1.XmlPullParserException : upon parsing response XML. |
|
ErrorResponseException : upon unsuccessful execution. |
|
InternalException : upon internal library error. |
Example
try {
// Check if my-bucket exists before removing it.
boolean found = minioClient.bucketExists("mybucket");
if (found) {
// Remove bucket my-bucketname. This operation will succeed only if the bucket is empty.
minioClient.removeBucket("mybucket");
System.out.println("mybucket is removed successfully");
} else {
System.out.println("mybucket does not exist");
}
} catch(MinioException e) {
System.out.println("Error occurred: " + e);
}
public Iterable<Result<Item>> listObjects(String bucketName, String prefix, boolean recursive, boolean useVersion1)
Lists all objects in a bucket.
Parameters
Param | Type | Description |
---|---|---|
bucketName |
String | Name of the bucket. |
prefix |
String | Prefix string. List objects whose name starts with prefix . |
recursive |
boolean | 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 with the same prefix up to the first '/' will be merged into one entry. |
useVersion1 |
boolean | when true, version 1 of REST API is used. |
Return Type | Exceptions |
---|---|
Iterable<Result<Item>> :an iterator of Result Items. |
None |
Example
try {
// Check whether 'mybucket' exists or not.
boolean found = minioClient.bucketExists("mybucket");
if (found) {
// List objects from 'my-bucketname'
Iterable<Result<Item>> myObjects = minioClient.listObjects("mybucket");
for (Result<Item> result : myObjects) {
Item item = result.get();
System.out.println(item.lastModified() + ", " + item.size() + ", " + item.objectName());
}
} else {
System.out.println("mybucket does not exist");
}
} catch (MinioException e) {
System.out.println("Error occurred: " + e);
}
public Iterable<Result<Upload>> listIncompleteUploads(String bucketName, String prefix, boolean recursive)
Lists partially uploaded objects in a bucket.
Parameters
Param | Type | Description |
---|---|---|
bucketName |
String | Name of the bucket. |
prefix |
String | Prefix string. List objects whose name starts with prefix . |
recursive |
boolean | 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 with the same prefix up to the first '/' will be merged into one entry. |
Return Type | Exceptions |
---|---|
Iterable<Result<Upload>> : an iterator of Upload. |
None |
Example
try {
// Check whether 'mybucket' exist or not.
boolean found = minioClient.bucketExists("mybucket");
if (found) {
// List all incomplete multipart upload of objects in 'my-bucketname
Iterable<Result<Upload>> myObjects = minioClient.listIncompleteUploads("mybucket");
for (Result<Upload> result : myObjects) {
Upload upload = result.get();
System.out.println(upload.uploadId() + ", " + upload.objectName());
}
} else {
System.out.println("mybucket does not exist");
}
} catch (MinioException e) {
System.out.println("Error occurred: " + e);
}
public PolicyType getBucketPolicy(String bucketName, String objectPrefix)
Get bucket policy at given objectPrefix.
Parameters
Param | Type | Description |
---|---|---|
bucketName |
String | Name of the bucket. |
objectPrefix |
String | Policy applies to objects with prefix. |
Return Type | Exceptions |
---|---|
PolicyType : The current bucket policy type for a given bucket and objectPrefix. |
Listed Exceptions: |
InvalidBucketNameException : upon invalid bucket name. |
|
NoResponseException : upon no response from server. |
|
IOException : upon connection error. |
|
org.xmlpull.v1.XmlPullParserException : upon parsing response XML. |
|
ErrorResponseException : upon unsuccessful execution. |
|
InternalException : upon internal library error. |
|
InvalidBucketNameException : upon invalid bucket name. |
|
InvalidObjectPrefixException : upon invalid object prefix. |
|
NoSuchAlgorithmException : upon requested algorithm was not found during signature calculation. |
|
InsufficientDataException : Thrown to indicate that reading given InputStream gets EOFException before reading given length. |
Example
try {
System.out.println("Current policy: " + minioClient.getBucketPolicy("myBucket", "downloads"));
} catch (MinioException e) {
System.out.println("Error occurred: " + e);
}
public void setBucketPolicy(String bucketName, String objectPrefix, PolicyType policy)
Set policy on bucket and object prefix.
Parameters
Param | Type | Description |
---|---|---|
bucketName |
String | Name of the bucket. |
objectPrefix |
String | Policy applies to objects with prefix. |
policy |
PolicyType | Policy to apply, available types are [PolicyType.NONE, PolicyType.READ_ONLY, PolicyType.READ_WRITE, PolicyType.WRITE_ONLY]. |
Return Type | Exceptions |
---|---|
None | Listed Exceptions: |
InvalidBucketNameException : upon invalid bucket name. |
|
NoResponseException : upon no response from server. |
|
IOException : upon connection error. |
|
org.xmlpull.v1.XmlPullParserException : upon parsing response XML. |
|
ErrorResponseException : upon unsuccessful execution. |
|
InternalException : upon internal library error. |
|
InvalidBucketNameException : upon invalid bucket name. |
|
InvalidObjectPrefixException : upon invalid object prefix. |
|
NoSuchAlgorithmException : upon requested algorithm was not found during signature calculation. |
|
InsufficientDataException : Thrown to indicate that reading given InputStream gets EOFException before reading given length. |
Example
try {
minioClient.setBucketPolicy("myBucket", "uploads", PolicyType.READ_ONLY);
} catch (MinioException e) {
System.out.println("Error occurred: " + e);
}
public InputStream getObject(String bucketName, String objectName, long offset)
Downloads an object as a stream.
Parameters
Param | Type | Description |
---|---|---|
bucketName |
String | Name of the bucket. |
objectName |
String | Object name in the bucket. |
Return Type | Exceptions |
---|---|
InputStream : InputStream containing the object data. |
Listed Exceptions: |
InvalidBucketNameException : upon invalid bucket name. |
|
NoResponseException : upon no response from server. |
|
IOException : upon connection error. |
|
org.xmlpull.v1.XmlPullParserException : upon parsing response XML. |
|
ErrorResponseException : upon unsuccessful execution. |
|
InternalException : upon internal library error. |
Example
try {
// Check whether the object exists using statObject().
// If the object is not found, statObject() throws an exception,
// else it means that the object exists.
// Execution is successful.
minioClient.statObject("mybucket", "myobject");
// Get input stream to have content of 'my-objectname' from 'my-bucketname'
InputStream stream = minioClient.getObject("mybucket", "myobject");
// Read the input stream and print to the console till EOF.
byte[] buf = new byte[16384];
int bytesRead;
while ((bytesRead = stream.read(buf, 0, buf.length)) >= 0) {
System.out.println(new String(buf, 0, bytesRead));
}
// Close the input stream.
stream.close();
} catch (MinioException e) {
System.out.println("Error occurred: " + e);
}
public InputStream getObject(String bucketName, String objectName, long offset, Long length)
Downloads the specified range bytes of an object as a stream.
Parameters
Param | Type | Description |
---|---|---|
bucketName |
String | Name of the bucket. |
objectName |
String | Object name in the bucket. |
offset |
Long | offset of the object from where the stream will start. |
length |
Long | length of the object that will be read in the stream (optional, if not specified we read the rest of the file from the offset). |
Return Type | Exceptions |
---|---|
InputStream : InputStream containing the object's data. |
Listed Exceptions: |
InvalidBucketNameException : upon invalid bucket name. |
|
NoResponseException : upon no response from server. |
|
IOException : upon connection error. |
|
org.xmlpull.v1.XmlPullParserException : upon parsing response XML. |
|
ErrorResponseException : upon unsuccessful execution. |
|
InternalException : upon internal library error. |
Example
try {
// Check whether the object exists using statObject().
// If the object is not found, statObject() throws an exception,
// else it means that the object exists.
// Execution is successful.
minioClient.statObject("mybucket", "myobject");
// Get input stream to have content of 'my-objectname' from 'my-bucketname'
InputStream stream = minioClient.getObject("mybucket", "myobject", 1024L, 4096L);
// Read the input stream and print to the console till EOF.
byte[] buf = new byte[16384];
int bytesRead;
while ((bytesRead = stream.read(buf, 0, buf.length)) >= 0) {
System.out.println(new String(buf, 0, bytesRead));
}
// Close the input stream.
stream.close();
} catch (MinioException e) {
System.out.println("Error occurred: " + e);
}
public void getObject(String bucketName, String objectName, String fileName)
Downloads and saves the object as a file in the local filesystem.
Parameters
Param | Type | Description |
---|---|---|
bucketName |
String | Name of the bucket. |
objectName |
String | Object name in the bucket. |
fileName |
String | File name. |
Return Type | Exceptions |
---|---|
None | Listed Exceptions: |
InvalidBucketNameException : upon invalid bucket name. |
|
NoResponseException : upon no response from server. |
|
IOException : upon connection error. |
|
org.xmlpull.v1.XmlPullParserException : upon parsing response XML. |
|
ErrorResponseException : upon unsuccessful execution. |
|
InternalException : upon internal library error. |
Example
try {
// Check whether the object exists using statObject().
// If the object is not found, statObject() throws an exception,
// else it means that the object exists.
// Execution is successful.
minioClient.statObject("mybucket", "myobject");
// Gets the object's data and stores it in photo.jpg
minioClient.getObject("mybucket", "myobject", "photo.jpg");
} catch (MinioException e) {
System.out.println("Error occurred: " + e);
}
public CipherInputStream getObject(String bucketName, String objectName, SecretKey key)
Gets entire encrypted object's data as InputStream in given bucket, then decrypts the content key associated with the encrypted object using the master key passed. Then creates a CipherInputStream composed of an InputStream and a Cipher. The Cipher is initialized for decryption using the content key, so the CipherInputStream will attempt to read in data and decrypt them, before returning the decrypted data. So that read() methods return processed, plain object.
The CipherInputStream must be closed after use else the connection will remain open.
Parameters
Param | Type | Description |
---|---|---|
bucketName |
String | Name of the bucket. |
objectName |
String | Object name in the bucket. |
key |
SecretKey | An object of type SecretKey. |
Return Type | Exceptions |
---|---|
None | Listed Exceptions: |
InvalidBucketNameException : upon invalid bucket name. |
|
NoResponseException : upon no response from server. |
|
IOException : upon connection error. |
|
org.xmlpull.v1.XmlPullParserException : upon parsing response XML. |
|
ErrorResponseException : upon unsuccessful execution. |
|
InternalException : upon internal library error. |
|
InvalidEncryptionMetadataException : upon encryption key/iv error |
|
BadPaddingException : upon wrong padding |
|
IllegalBlockSizeException : upon incorrect block size |
|
NoSuchPaddingException : upon incorrect padding |
|
InvalidAlgorithmParameterException : upon incorrect algorithm |
Example
try {
// Check whether the object exists using statObject().
// If the object is not found, statObject() throws an exception,
// else it means that the object exists.
// Execution is successful.
minioClient.statObject("mybucket", "myobject");
//Generate symmetric 256 bit AES key.
KeyGenerator symKeyGenerator = KeyGenerator.getInstance("AES");
symKeyGenerator.init(256);
SecretKey symKey = symKeyGenerator.generateKey();
// Gets the object's data and stores it in photo.jpg
InputStream stream = minioClient.getObject("testbucket", "my-objectname", symKey);
// Read the input stream and print to the console till EOF.
byte[] buf = new byte[16384];
int bytesRead;
while ((bytesRead = stream.read(buf, 0, buf.length)) >= 0) {
System.out.println(new String(buf, 0, bytesRead, StandardCharsets.UTF_8));
}
// Close the input stream.
stream.close();
} catch (MinioException e) {
System.out.println("Error occurred: " + e);
}
public InputStream getObject(String bucketName, String objectName, KeyPair key)
Gets entire encrypted object's data as InputStream in given bucket, then decrypts the content key associated with the encrypted object using the master key pair passed. Then creates a CipherInputStream composed of an InputStream and a Cipher. The Cipher is initialized for decryption using the content key, so the CipherInputStream will attempt to read in data and decrypt them, before returning the decrypted data. So that read() methods return processed, plain object.
The CipherInputStream must be closed after use else the connection will remain open.
Parameters
Param | Type | Description |
---|---|---|
bucketName |
String | Name of the bucket. |
objectName |
String | Object name in the bucket. |
key |
KeyPair | An object of type RSA KeyPair. |
Return Type | Exceptions |
---|---|
None | Listed Exceptions: |
InvalidBucketNameException : upon invalid bucket name. |
|
NoResponseException : upon no response from server. |
|
IOException : upon connection error. |
|
org.xmlpull.v1.XmlPullParserException : upon parsing response XML. |
|
ErrorResponseException : upon unsuccessful execution. |
|
InternalException : upon internal library error. |
|
InvalidEncryptionMetadataException : upon encryption key/iv error |
|
BadPaddingException : upon wrong padding |
|
IllegalBlockSizeException : upon incorrect block size |
|
NoSuchPaddingException : upon incorrect padding |
|
InvalidAlgorithmParameterException : upon incorrect algorithm |
Example
try {
// Check whether the object exists using statObject().
// If the object is not found, statObject() throws an exception,
// else it means that the object exists.
// Execution is successful.
minioClient.statObject("mybucket", "myobject");
KeyPairGenerator keyGenerator = KeyPairGenerator.getInstance("RSA");
keyGenerator.initialize(1024, new SecureRandom());
KeyPair keypair = keyGenerator.generateKeyPair();
// Gets the object's data and stores it in photo.jpg
InputStream stream = minioClient.getObject("testbucket", "my-objectname", keypair);
// Read the input stream and print to the console till EOF.
byte[] buf = new byte[16384];
int bytesRead;
while ((bytesRead = stream.read(buf, 0, buf.length)) >= 0) {
System.out.println(new String(buf, 0, bytesRead, StandardCharsets.UTF_8));
}
// Close the input stream.
stream.close();
} catch (MinioException e) {
System.out.println("Error occurred: " + e);
}
public void putObject(String bucketName, String objectName, InputStream stream, long size, String contentType)
Uploads an object from an InputStream.
Parameters
Param | Type | Description |
---|---|---|
bucketName |
String | Name of the bucket. |
objectName |
String | Object name in the bucket. |
stream |
InputStream | stream to upload. |
size |
long | Size of the data to read from stream that will be uploaded. |
contentType |
String | Content type of the stream. |
Return Type | Exceptions |
---|---|
None | Listed Exceptions: |
InvalidBucketNameException : upon invalid bucket name. |
|
NoResponseException : upon no response from server. |
|
IOException : upon connection error. |
|
org.xmlpull.v1.XmlPullParserException : upon parsing response XML. |
|
ErrorResponseException : upon unsuccessful execution. |
|
InternalException : upon internal library error. |
Example
The maximum size of a single object is limited to 5TB. putObject transparently uploads objects larger than 5MiB in multiple parts. This allows failed uploads to resume safely by only uploading the missing parts. Uploaded data is carefully verified using MD5SUM signatures.
try {
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 an object
minioClient.putObject("mybucket", "myobject", bais, bais.available(), "application/octet-stream");
bais.close();
System.out.println("myobject is uploaded successfully");
} catch(MinioException e) {
System.out.println("Error occurred: " + e);
}
public void putObject(String bucketName, String objectName, String fileName)
Uploads contents from a file to objectName. View Javadoc
Parameters
Param | Type | Description |
---|---|---|
bucketName |
String | Name of the bucket. |
objectName |
String | Object name in the bucket. |
fileName |
String | File name. |
Return Type | Exceptions |
---|---|
None | Listed Exceptions: |
InvalidBucketNameException : upon invalid bucket name. |
|
NoResponseException : upon no response from server. |
|
IOException : upon connection error. |
|
org.xmlpull.v1.XmlPullParserException : upon parsing response XML. |
|
ErrorResponseException : upon unsuccessful execution. |
|
InternalException : upon internal library error. |
Example
The maximum size of a single object is limited to 5TB. putObject transparently uploads objects larger than 5MB in multiple parts. This allows failed uploads to resume safely by only uploading the missing parts. Uploaded data is carefully verified using MD5SUM signatures.
try {
minioClient.putObject("mybucket", "island.jpg", "/mnt/photos/island.jpg")
System.out.println("island.jpg is uploaded successfully");
} catch(MinioException e) {
System.out.println("Error occurred: " + e);
}
putObject(String bucketName, String objectName, InputStream stream, long size, String contentType, SecretKey key)
public void putObject(String bucketName, String objectName, InputStream stream, long size, String contentType, SecretKey key)
Takes data from given stream, encrypts it using a random content key and uploads it as object to given bucket. Also uploads the encrypted content key and iv as header of the encrypted object. The content key is encrypted using the master key passed to this function.
If the object is larger than 525MB, the client will automatically perform multi part upload.
Parameters
Param | Type | Description |
---|---|---|
bucketName |
String | Name of the bucket. |
objectName |
String | Object name in the bucket. |
stream |
InputStream | stream to upload. |
size |
long | Size of the data to read from stream that will be uploaded. |
contentType |
String | Content type of the stream. |
key |
SecretKey | An object of type initialized with AES SecretKey. |
Return Type | Exceptions |
---|---|
None | Listed Exceptions: |
InvalidBucketNameException : upon invalid bucket name. |
|
NoResponseException : upon no response from server. |
|
IOException : upon connection error. |
|
org.xmlpull.v1.XmlPullParserException : upon parsing response XML. |
|
ErrorResponseException : upon unsuccessful execution. |
|
InternalException : upon internal library error. |
|
InvalidAlgorithmParameterException : upon wrong encryption algorithm used. |
|
BadPaddingException : upon incorrect padding in a block. |
|
IllegalBlockSizeException : upon incorrect block. |
|
NoSuchPaddingException : upon wrong padding type specified. |
Example
Object is encrypted using a randomly generated data encryption key. The data encryption key is then encrypted using a master key known only to the client (wrapped in encryptionMaterials object). The encrypted data encryption key is uploaded as the object header along with the IV used and the encrypted object to the remote server.
try {
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"));
//Generate symmetric 256 bit AES key.
KeyGenerator symKeyGenerator = KeyGenerator.getInstance("AES");
symKeyGenerator.init(256);
SecretKey symKey = symKeyGenerator.generateKey();
// Create an object
minioClient.putObject("mybucket", "myobject", bais, bais.available(), "application/octet-stream", symKey);
bais.close();
System.out.println("myobject is uploaded successfully");
} catch(MinioException e) {
System.out.println("Error occurred: " + e);
}
putObject(String bucketName, String objectName, InputStream stream, long size, String contentType, KeyPair key)
public void putObject(String bucketName, String objectName, InputStream stream, long size, String contentType, KeyPair key)
Takes data from given stream, encrypts it using a random content key and uploads it as object to given bucket. Also uploads the encrypted content key and iv as header of the encrypted object. The content key is encrypted using the master key pair passed to this function.
If the object is larger than 525MB, the client will automatically perform multi part upload.
Parameters
Param | Type | Description |
---|---|---|
bucketName |
String | Name of the bucket. |
objectName |
String | Object name in the bucket. |
stream |
InputStream | stream to upload. |
size |
long | Size of the data to read from stream that will be uploaded. |
contentType |
String | Content type of the stream. |
key |
KeyPair | An object of type initialized RSA KeyPair. |
Return Type | Exceptions |
---|---|
None | Listed Exceptions: |
InvalidBucketNameException : upon invalid bucket name. |
|
NoResponseException : upon no response from server. |
|
IOException : upon connection error. |
|
org.xmlpull.v1.XmlPullParserException : upon parsing response XML. |
|
ErrorResponseException : upon unsuccessful execution. |
|
InternalException : upon internal library error. |
|
InvalidAlgorithmParameterException : upon wrong encryption algorithm used. |
|
BadPaddingException : upon incorrect padding in a block. |
|
IllegalBlockSizeException : upon incorrect block. |
|
NoSuchPaddingException : upon wrong padding type specified. |
Example
Object is encrypted using a randomly generated data encryption key. The data encryption key is then encrypted using a master key known only to the client (wrapped in encryptionMaterials object). The encrypted data encryption key is uploaded as the object header along with the IV used and the encrypted object to the remote server.
try {
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"));
KeyPairGenerator keyGenerator = KeyPairGenerator.getInstance("RSA");
keyGenerator.initialize(1024, new SecureRandom());
KeyPair keypair = keyGenerator.generateKeyPair();
// Create an object
minioClient.putObject("mybucket", "myobject", bais, bais.available(), "application/octet-stream", keypair);
bais.close();
System.out.println("myobject is uploaded successfully");
} catch(MinioException e) {
System.out.println("Error occurred: " + e);
}
public ObjectStat statObject(String bucketName, String objectName)
Gets metadata of an object.
Parameters
Param | Type | Description |
---|---|---|
bucketName |
String | Name of the bucket. |
objectName |
String | Object name in the bucket. |
Return Type | Exceptions |
---|---|
ObjectStat : Populated object meta data. |
Listed Exceptions: |
InvalidBucketNameException : upon invalid bucket name. |
|
NoResponseException : upon no response from server. |
|
IOException : upon connection error. |
|
org.xmlpull.v1.XmlPullParserException : upon parsing response XML. |
|
ErrorResponseException : upon unsuccessful execution. |
|
InternalException : upon internal library error. |
Example
try {
// Get the metadata of the object.
ObjectStat objectStat = minioClient.statObject("mybucket", "myobject");
System.out.println(objectStat);
} catch(MinioException e) {
System.out.println("Error occurred: " + e);
}
copyObject(String bucketName, String objectName, String destBucketName, String destObjectName, CopyConditions cpConds, Map<String, String> metadata)
public void copyObject(String bucketName, String objectName, String destBucketName, String destObjectName, CopyConditions cpConds, Map<String, String> metadata)
Copies content from objectName to destObjectName.
Parameters
Param | Type | Description |
---|---|---|
bucketName |
String | Name of the source bucket. |
objectName |
String | Object name in the source bucket to be copied. |
destBucketName |
String | Destination bucket name. |
destObjectName |
String | Destination object name to be created, if not provided defaults to source object name. |
copyConditions |
CopyConditions | Map of conditions useful for applying restrictions on copy operation. |
metadata |
Map | Map of object metadata for destination object. |
Return Type | Exceptions |
---|---|
None | Listed Exceptions: |
InvalidBucketNameException : upon invalid bucket name. |
|
NoResponseException : upon no response from server. |
|
IOException : upon connection error. |
|
org.xmlpull.v1.XmlPullParserException : upon parsing response XML. |
|
ErrorResponseException : upon unsuccessful execution. |
|
InternalException : upon internal library error. |
Example
This API performs a server side copy operation from a given source object to destination object.
try {
CopyConditions copyConditions = new CopyConditions();
copyConditions.setMatchETagNone("TestETag");
minioClient.copyObject("mybucket", "island.jpg", "mydestbucket", "processed.png", copyConditions);
System.out.println("island.jpg is uploaded successfully");
} catch(MinioException e) {
System.out.println("Error occurred: " + e);
}
public void removeObject(String bucketName, String objectName)
Removes an object.
Parameters
Param | Type | Description |
---|---|---|
bucketName |
String | Name of the bucket. |
objectName |
String | Object name in the bucket. |
Return Type | Exceptions |
---|---|
None | Listed Exceptions: |
InvalidBucketNameException : upon invalid bucket name. |
|
NoResponseException : upon no response from server. |
|
IOException : upon connection error. |
|
org.xmlpull.v1.XmlPullParserException : upon parsing response XML. |
|
ErrorResponseException : upon unsuccessful execution. |
|
InternalException : upon internal library error. |
Example
try {
// Remove my-objectname from the bucket my-bucketname.
minioClient.removeObject("mybucket", "myobject");
System.out.println("successfully removed mybucket/myobject");
} catch (MinioException e) {
System.out.println("Error: " + e);
}
public Iterable<Result<DeleteError>> removeObject(String bucketName, Iterable<String> objectNames)
Removes multiple objects.
Parameters
Param | Type | Description |
---|---|---|
bucketName |
String | Name of the bucket. |
objectNames |
Iterable | Iterable object contains object names for removal. |
Return Type | Exceptions |
---|---|
Iterable<Result<DeleteError>> :an iterator of Result DeleteError. |
None |
Example
List<String> objectNames = new LinkedList<String>();
objectNames.add("my-objectname1");
objectNames.add("my-objectname2");
objectNames.add("my-objectname3");
try {
// Remove object all objects in objectNames list from the bucket my-bucketname.
for (Result<DeleteError> errorResult: minioClient.removeObject("my-bucketname", objectNames)) {
DeleteError error = errorResult.get();
System.out.println("Failed to remove '" + error.objectName() + "'. Error:" + error.message());
}
} catch (MinioException e) {
System.out.println("Error: " + e);
}
public void removeIncompleteUpload(String bucketName, String objectName)
Removes a partially uploaded object.
Parameters
Param | Type | Description |
---|---|---|
bucketName |
String | Name of the bucket. |
objectName |
String | Object name in the bucket. |
Return Type | Exceptions |
---|---|
None | Listed Exceptions: |
InvalidBucketNameException : upon invalid bucket name. |
|
NoResponseException : upon no response from server. |
|
IOException : upon connection error. |
|
org.xmlpull.v1.XmlPullParserException : upon parsing response XML. |
|
ErrorResponseException : upon unsuccessful execution. |
|
InternalException : upon internal library error. |
Example
try {
// Removes partially uploaded objects from buckets.
minioClient.removeIncompleteUpload("mybucket", "myobject");
System.out.println("successfully removed all incomplete upload session of my-bucketname/my-objectname");
} catch(MinioException e) {
System.out.println("Error occurred: " + e);
}
public String presignedGetObject(String bucketName, String objectName, Integer expires)
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
Param | 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. |
Return Type | Exceptions |
---|---|
String : string contains URL to download the object. |
Listed Exceptions: |
InvalidBucketNameException : upon invalid bucket name. |
|
InvalidKeyException : upon an invalid access key or secret key. |
|
IOException : upon connection error. |
|
NoSuchAlgorithmException : upon requested algorithm was not found during signature calculation. |
|
InvalidExpiresRangeException : upon input expires is out of range. |
Example
try {
String url = minioClient.presignedGetObject("mybucket", "myobject", 60 * 60 * 24);
System.out.println(url);
} catch(MinioException e) {
System.out.println("Error occurred: " + e);
}
public String presignedPutObject(String bucketName, String objectName, Integer expires)
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
Param | 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. |
Return Type | Exceptions |
---|---|
String : string contains URL to download the object. |
Listed Exceptions: |
InvalidBucketNameException : upon invalid bucket name. |
|
InvalidKeyException : upon an invalid access key or secret key. |
|
IOException : upon connection error. |
|
NoSuchAlgorithmException : upon requested algorithm was not found during signature calculation. |
|
InvalidExpiresRangeException : upon input expires is out of range. |
Example
try {
String url = minioClient.presignedPutObject("mybucket", "myobject", 60 * 60 * 24);
System.out.println(url);
} catch(MinioException e) {
System.out.println("Error occurred: " + e);
}
public Map<String,String> presignedPostPolicy(PostPolicy policy)
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.
Parameters
Param | Type | Description |
---|---|---|
policy |
PostPolicy | Post policy of an object. |
Return Type | Exceptions |
---|---|
Map : Map of strings to construct form-data. |
Listed Exceptions: |
InvalidBucketNameException : upon invalid bucket name. |
|
InvalidKeyException : upon an invalid access key or secret key. |
|
IOException : upon connection error. |
|
NoSuchAlgorithmException : upon requested algorithm was not found during signature calculation. |
Example
try {
PostPolicy policy = new PostPolicy("mybucket", "myobject",
DateTime.now().plusDays(7));
policy.setContentType("image/png");
Map<String,String> formData = minioClient.presignedPostPolicy(policy);
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/mybucket");
} catch(MinioException e) {
System.out.println("Error occurred: " + e);