forked from vehery/Signal-Setup-Guide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUrlSigner.java
executable file
·42 lines (30 loc) · 1.43 KB
/
UrlSigner.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
// service/src/main/java/org/whispersystems/textsecuregcm/s3/UrlSigner.java
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import org.xmlpull.v1.XmlPullParserException;
import io.minio.MinioClient;
import io.minio.errors.MinioException;
public String getPreSignedUrl(long attachmentId, HttpMethod method) throws InvalidKeyException, NoSuchAlgorithmException, IOException, XmlPullParserException, MinioException {
String request = geturl(bucket, String.valueOf(attachmentId), method);
return request;
}
public String geturl( String bucketname, String attachemtnId, HttpMethod method) throws NoSuchAlgorithmException,
IOException, InvalidKeyException, XmlPullParserException, MinioException {
String url = null;
MinioClient minioClient = new MinioClient("https://localhost:9000", "XXXXX-MINIO-ACCESS_KEY-XXXXXX", "XXXXX-MINIO-ACCESS_SECRET-XXXXXX");
try {
if(method==HttpMethod.PUT){
url = minioClient.presignedPutObject(bucketname, attachemtnId, 60 * 60 * 24);
}
if(method==HttpMethod.GET){
url = minioClient.presignedGetObject(bucketname, attachemtnId);
}
System.out.println(url);
} catch(MinioException e) {
System.out.println("Error occurred: " + e);
} catch (java.security.InvalidKeyException e) {
e.printStackTrace();
}
return url;
}