1、先看下官方文档
AWS S3V4 DEMO
2、实际调用试试
1)代码
// 计算auth// for a simple GET, we have no body so supply the precomputed 'empty' hashMap<String, String> headers = new HashMap<String, String>();headers.put("x-amz-content-sha256", AWS4SignerBase.EMPTY_BODY_SHA256);headers.put("x-amz-date","20231212T013128Z");// 如果是putObject,并且只有minio才多计算String md5Hash = Digest.ZERO_MD5_HASH;headers.put("Content-MD5",md5Hash);URL endpointUrl = new URL("http://192.168.21.61:9000/aaa/client_1/20231201/2023120110242247663528991.jpg");String regionName = "us-east-1";AWS4SignerForAuthorizationHeader signer = new AWS4SignerForAuthorizationHeader(endpointUrl, "GET", "s3", regionName);String authorization = signer.computeSignature(headers,null, // no query parametersAWS4SignerBase.EMPTY_BODY_SHA256,"aaa","aaa@12345");log.info("authorization={}",authorization);// place the computed signature into a formatted 'Authorization' header// and call S3headers.put("Authorization", authorization);
2)需要微调的地方
3、与MINIO不同的地方
minio调用流程,以getObject为例子
io.minio.MinioClient#getObject ->
io.minio.MinioAsyncClient#getObject ->
io.minio.S3Base#executeAsync(io.minio.http.Method, io.minio.BaseArgs, com.google.common.collect.Multimap<java.lang.String,java.lang.String>, com.google.common.collect.Multimap<java.lang.String,java.lang.String>, java.lang.Object, int) ->
io.minio.S3Base#executeAsync(io.minio.http.Method, java.lang.String, java.lang.String, java.lang.String, okhttp3.Headers, com.google.common.collect.Multimap<java.lang.String,java.lang.String>, java.lang.Object, int) ->
重点
分别设置头信息与签名
与AWS官方demo不同,里面会对header中的Content-MD5单独做个计算。
如果想要计算拉通,需要手动对其单独计算一下。