The MinIO Java Client SDK provides simple APIs to access any Amazon S3 compatible object storage server.
This quickstart guide will show you how to install the client SDK and execute an example java program. For a complete list of APIs and examples, please take a look at the Java Client API Reference documentation.
Java 1.8 or above, with one of the following environments:
<dependency>
<groupId>io.minio</groupId>
<artifactId>minio</artifactId>
<version>7.0.2</version>
</dependency>
dependencies {
compile 'io.minio:minio:7.0.2'
}
You can download the latest JAR directly from maven.
This example program connects to an object storage server, makes a bucket on the server and then uploads a file to the bucket.
You need three items in order to connect to an object storage server.
Params | Description |
---|---|
Endpoint | URL to object storage service. |
Access Key | Access key is like user ID that uniquely identifies your account. |
Secret Key | Secret key is the password to your account. |
For the following example, we will use a freely hosted MinIO server running at https://play.min.io. Feel free to use this service for test and development. Access credentials shown in this example are open to the public.
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.security.InvalidKeyException;
import org.xmlpull.v1.XmlPullParserException;
import io.minio.MinioClient;
import io.minio.errors.MinioException;
public class FileUploader {
public static void main(String[] args) throws NoSuchAlgorithmException, IOException, InvalidKeyException, XmlPullParserException {
try {
// Create a minioClient with the MinIO Server name, Port, Access key and Secret key.
MinioClient minioClient = new MinioClient("https://play.min.io", "Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
// Check if the bucket already exists.
boolean isExist = minioClient.bucketExists("asiatrip");
if(isExist) {
System.out.println("Bucket already exists.");
} else {
// Make a new bucket called asiatrip to hold a zip file of photos.
minioClient.makeBucket("asiatrip");
}
// Upload the zip file to the bucket with putObject
minioClient.putObject("asiatrip","asiaphotos.zip", "/home/user/Photos/asiaphotos.zip", null);
System.out.println("/home/user/Photos/asiaphotos.zip is successfully uploaded as asiaphotos.zip to `asiatrip` bucket.");
} catch(MinioException e) {
System.out.println("Error occurred: " + e);
}
}
}
javac -cp "minio-7.0.2-all.jar" FileUploader.java
java -cp "minio-7.0.2-all.jar:." FileUploader
/home/user/Photos/asiaphotos.zip is successfully uploaded as asiaphotos.zip to `asiatrip` bucket.
mc ls play/asiatrip/
[2016-06-02 18:10:29 PDT] 82KiB asiaphotos.zip
The full API Reference is available here.
- ListBuckets.java
- ListObjects.java
- BucketExists.java
- MakeBucket.java
- RemoveBucket.java
- ListIncompleteUploads.java
- PutObject.java
- PutObjectEncrypted.java
- GetObject.Java
- GetObjectEncrypted.Java
- GetPartialObject.java
- RemoveObject.java
- RemoveObjects.java
- StatObject.java
- CopyObjectEncrypted.java
- CopyObjectEncryptedKms.java
- CopyObjectEncryptedS3.java
- PutGetObjectEncrypted.java
- PutObjectEncryptedKms.java
- PutObjectEncryptedS3.java