Java SDK QuickStart

Minimum Requirements

Java 1.8 or above, with one of the following environments:

Download from maven

1
Copy<dependency>
2
<groupId>io.minio</groupId>
3
<artifactId>minio</artifactId>
4
<version>7.1.0</version>
5
</dependency>
Copied!

Download from gradle

1
Copydependencies {
2
compile 'io.minio:minio:7.1.0'
3
}
Copied!

Download from JAR

You can download the latest JAR directly from maven.

Quick Start Example - File Uploader

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.
Make sure you have an OSS service running for this example.
1
import java.io.IOException;
2
import java.security.NoSuchAlgorithmException;
3
import java.security.InvalidKeyException;
4
5
import org.xmlpull.v1.XmlPullParserException;
6
7
import io.minio.MinioClient;
8
import io.minio.errors.MinioException;
9
10
public class FileUploader {
11
public static void main(String[] args) throws NoSuchAlgorithmException, IOException, InvalidKeyException, XmlPullParserException {
12
try {
13
// Create a minioClient with the MinIO Server name, Port, Access key and Secret key.
14
MinioClient minioClient = new MinioClient("https://storage-4175974314028753.cloud.bigconnect.io", "Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
15
16
// Check if the bucket already exists.
17
boolean isExist =
18
minioClient.bucketExists(BucketExistsArgs.builder().bucket("asiatrip").build());
19
if(isExist) {
20
System.out.println("Bucket already exists.");
21
} else {
22
// Make a new bucket called asiatrip to hold a zip file of photos.
23
minioClient.makeBucket(MakeBucketArgs.builder().bucket("asiatrip").build());
24
}
25
26
// Upload the zip file to the bucket with putObject
27
minioClient.putObject("asiatrip","asiaphotos.zip", "/home/user/Photos/asiaphotos.zip", null);
28
System.out.println("/home/user/Photos/asiaphotos.zip is successfully uploaded as asiaphotos.zip to `asiatrip` bucket.");
29
} catch(MinioException e) {
30
System.out.println("Error occurred: " + e);
31
}
32
}
33
}
34
Copied!
Compile FileUploader
1
Copyjavac -cp "minio-7.1.0-all.jar" FileUploader.java
Copied!
Run FileUploader
1
Copyjava -cp "minio-7.1.0-all.jar:." FileUploader
2
/home/user/Photos/asiaphotos.zip is successfully uploaded as asiaphotos.zip to `asiatrip` bucket.
3
4
osscli ls play/asiatrip/
5
[2016-06-02 18:10:29 PDT] 82KiB asiaphotos.zip
Copied!
Have a look at the Java SDK Reference for more information.
Last modified 1yr ago