-
Notifications
You must be signed in to change notification settings - Fork 0
/
MinIo.java
94 lines (84 loc) · 3.23 KB
/
MinIo.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package org.folio.folio_export_aws;
import io.minio.MinioClient;
import io.minio.PutObjectOptions;
import io.minio.errors.*;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import org.xmlpull.v1.XmlPullParserException;
public class MinIo {
public static void main(String[] args)
throws IOException, NoSuchAlgorithmException, InvalidKeyException, XmlPullParserException {
String bucketName = "test";
try {
/* play.min.io for test and development. */
MinioClient minioClient =
new MinioClient(
"http://127.0.0.1:9001",
"minioadmin",
"minioadmin");
/* Amazon S3: */
// MinioClient minioClient = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID",
// "YOUR-SECRETACCESSKEY");
// Create some content for the object.
StringBuilder builder = new StringBuilder();
for (int i = 0; i < 1000; i++) {
builder.append(
"Testing minio using a docker on my local MAC ");
builder.append("(29 letters)\n");
builder.append("---\n");
}
// Create a InputStream for object upload.
ByteArrayInputStream bais = new ByteArrayInputStream(builder.toString().getBytes("UTF-8"));
// Create object 'my-objectname' in 'my-bucketname' with content from the input stream.
minioClient.putObject(
bucketName, "testkv", bais, new PutObjectOptions(bais.available(), -1));
bais.close();
System.out.println("my-objectname is uploaded successfully");
String URL = getPreSignedURL(minioClient, bucketName, "testkv");
System.out.println("PreSigned URL "+ URL);
} catch (MinioException e) {
System.out.println("Error occurred: " + e);
}
}
public static String getPreSignedURL(MinioClient minioClient,String bucketName,String keyName) {
try {
return minioClient.presignedGetObject(bucketName, keyName, 60 * 60 * 24);
} catch (InvalidKeyException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvalidBucketNameException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InsufficientDataException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XmlParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ErrorResponseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InternalException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvalidExpiresRangeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvalidResponseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
}