以下是生成上传下载签名方法:
void contextLoads() {
String SIGN = "";
Map<String, String> reqParams = new HashMap<String, String>();
reqParams.put("response-content-type", "application/json");
SIGN = minIoUtil.getMinIoClient().getPresignedObjectUrl(
GetPresignedObjectUrlArgs.builder()
.method(Method.GET)
.bucket("images")
.object("1.jpg")
.expiry(1, TimeUnit.DAYS)
.build()
);
log.info("下载地址:" +SIGN);
SIGN = minIoUtil.getMinIoClient().getPresignedObjectUrl(
GetPresignedObjectUrlArgs.builder()
.method(Method.PUT)
.bucket("images")
.object("1.jpg")
.expiry(1, TimeUnit.DAYS)
.extraQueryParams(reqParams)
.build()
);
log.info("上传地址:" +SIGN);
}
以下是官网生成上传下载签名方法
// Get presigned URL string to upload 'my-objectname' in 'my-bucketname'
// with response-content-type as application/json and life time as one day.
Map<String, String> reqParams = new HashMap<String, String>();
reqParams.put("response-content-type", "application/json");
String url =
minioClient.getPresignedObjectUrl(
GetPresignedObjectUrlArgs.builder()
.method(Method.PUT)
.bucket("my-bucketname")
.object("my-objectname")
.expiry(1, TimeUnit.DAYS)
.extraQueryParams(reqParams)
.build());
System.out.println(url);
// Get presigned URL string to download 'my-objectname' in 'my-bucketname' and its life time
// is 2 hours.
String url =
minioClient.getPresignedObjectUrl(
GetPresignedObjectUrlArgs.builder()
.method(Method.GET)
.bucket("my-bucketname")
.object("my-objectname")
.expiry(2, TimeUnit.HOURS)
.build());
System.out.println(url);
我生成的上传下载签名地址:
下载地址:http://110.42.220.76:9000/images/1.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=shuai%2F20211111%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20211111T083356Z&X-Amz-Expires=86400&X-Amz-SignedHeaders=host&X-Amz-Signature=ad84c7b848c74b4cdd25dd509a8e3a31506e239788d099dfa9ba863e5a6fc141
上传地址:http://110.42.220.76:9000/images/1.jpg?response-content-type=application%2Fjson&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=shuai%2F20211111%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20211111T083356Z&X-Amz-Expires=86400&X-Amz-SignedHeaders=host&X-Amz-Signature=f6a009d61ab1595bb794afb6b9a50e1eaa62e333e53c3ccfc559830c1d362b60
上传下载报签名不匹配