Java Client API Reference Slack

Initialize Minio Client object.

Minio

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

AWS S3

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

1. Constructors

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

Minio

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

AWS S3

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

2. Bucket operations

makeBucket(String bucketName)

public void makeBucket(String bucketName)

Creates a new bucket.

View Javadoc

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

listBuckets()

public List<Bucket> listBuckets()

Lists all buckets.

View Javadoc

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

bucketExists(String bucketName)

public boolean bucketExists(String bucketName)

Checks if a bucket exists.

View Javadoc

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

removeBucket(String bucketName)

public void removeBucket(String bucketName)

Removes a bucket.

View Javadoc

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

listObjects(String bucketName, String prefix, boolean recursive)

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

Lists all objects in a bucket.

View Javadoc

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

listIncompleteUploads(String bucketName, String prefix, boolean recursive)

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

Lists partially uploaded objects in a bucket.

View Javadoc

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

getBucketPolicy(String bucketName, String objectPrefix)

public BucketPolicy getBucketPolicy(String bucketName, String objectPrefix)

Get bucket policy at given objectPrefix.

View Javadoc

Parameters

Param Type Description
bucketName String Name of the bucket.
objectPrefix String Policy applies to objects with prefix.
Return Type Exceptions
BucketPolicy: The current bucket policy for 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);
}

setBucketPolicy(String bucketName, String objectPrefix, BucketPolicy bucketPolicy)

public void setBucketPolicy(String bucketName, String objectPrefix, BucketPolicy bucketPolicy)

Set policy on bucket and object prefix.

View Javadoc

Parameters

Param Type Description
bucketName String Name of the bucket.
objectPrefix String Policy applies to objects with prefix.
bucketPolicy BucketPolicy Policy to apply.
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", BucketPolicy.WriteOnly);
} catch (MinioException e) {
  System.out.println("Error occurred: " + e);
}

3. Object operations

getObject(String bucketName, String objectName)

public InputStream getObject(String bucketName, String objectName, long offset)

Downloads an object as a stream.

View Javadoc

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

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

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

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

View Javadoc

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

getObject(String bucketName, String objectName, String fileName)

public void getObject(String bucketName, String objectName, String fileName)

Downloads and saves the object as a file in the local filesystem.

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

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

putObject(String bucketName, String objectName, InputStream stream, long size, String contentType)

public void putObject(String bucketName, String objectName, InputStream stream, long size, String contentType)

Uploads an object from an InputStream.

View Javadoc

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

putObject(String bucketName, String objectName, String fileName)

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

statObject(String bucketName, String objectName)

public ObjectStat statObject(String bucketName, String objectName)

Gets metadata of an object.

View Javadoc

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)

public void copyObject(String bucketName, String objectName, String destBucketName, String destObjectName, CopyConditions cpConds)

Copies content from objectName to destObjectName.

View Javadoc

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.
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);
}

removeObject(String bucketName, String objectName)

public void removeObject(String bucketName, String objectName)

Removes an object.

View Javadoc

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

removeIncompleteUpload(String bucketName, String objectName)

public void removeIncompleteUpload(String bucketName, String objectName)

Removes a partially uploaded object.

View Javadoc

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

4. Presigned operations

presignedGetObject(String bucketName, String objectName, Integer expires)

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.

View Javadoc

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

presignedPutObject(String bucketName, String objectName, Integer expires)

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.

View Javadoc

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

presignedPostPolicy(PostPolicy policy)

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.

View Javadoc

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

5. Explore Further