新建MinioAsyncClient子类,重载getPresignedObjectUrl 方法
public class CustomizedClient extends MinioAsyncClient {
private String domainUrl;
public CustomizedClient(MinioAsyncClient client) {
super(client);
}
public String getPresignedObjectPublicUrl(GetPresignedObjectUrlArgs args) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException,
InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
return getPresignedObjectUrl(args, domainUrl);
}
public String getPresignedObjectUrl(GetPresignedObjectUrlArgs args, String domainUrl)
throws ErrorResponseException, InsufficientDataException, InternalException,
InvalidKeyException, InvalidResponseException, IOException,NoSuchAlgorithmException,
XmlParserException, ServerException {
checkArgs(args);
byte[] body = (args.method() == Method.PUT || args.method() == Method.POST) ? EMPTY_BODY : null;
Multimap<String, String> queryParams = newMultimap(args.extraQueryParams());
if (args.versionId() != null) {
queryParams.put("versionId", args.versionId());
}
String region = getRegion(args.bucket(), args.region());
if (provider == null) {
HttpUrl url = buildUrl(args.method(), args.bucket(), args.object(), region, queryParams);
return url.toString();
}
Credentials creds = provider.fetch();
if (creds.sessionToken() != null) {
queryParams.put("X-Amz-Security-Token", creds.sessionToken());
}
HttpUrl url = buildUrl(args.method(), args.bucket(), args.object(), region, queryParams);
String withoutPort = domainUrl;
if (endpoint != null) {
url = url.newBuilder(url.toString().replace(baseUrl.toString(), withoutPort + File.separator)).build();
}
Request request =
createRequest(
url,
args.method(),
args.extraHeaders() == null ? null : httpHeaders(args.extraHeaders()),
body,
0,
creds);
url = Signer.presignV4(request, region, creds.accessKey(), creds.secretKey(), args.expiry());
return url.toString().replace(withoutPort, domainUrl);
}
}
配置类
@Configuration
public class Config {
@Bean
public CustomizedClient customizedClient() {
CustomizedClient customizedClient = new CustomizedClient(asyncClient());
customizedClient.setDomainUrl("url");
return customizedClient;
}
@Bean
public MinioAsyncClient asyncClient() {
MinioAsyncClient.Builder minioClientBuilder = MinioAsyncClient.builder();
return minioClientBuilder.endpoint("url").credentials("ak", "sk").build();
}
}