有关内网问题 解决
This commit is contained in:
parent
c796ee2ab6
commit
a71efab417
|
|
@ -37,6 +37,11 @@ public class MinioConfig
|
|||
* 存储桶名称
|
||||
*/
|
||||
private String bucketName;
|
||||
/**
|
||||
*
|
||||
* 内网IP地址
|
||||
*/
|
||||
private String endpointInter;
|
||||
|
||||
@Bean
|
||||
public MinioClient getMinioClient()
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import javax.annotation.Resource;
|
|||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
|
@ -303,9 +304,25 @@ public class MinioUtil {
|
|||
if (StringUtils.isNotEmpty(fileUrl)){
|
||||
if (fileUrl.startsWith("http://")) {
|
||||
return fileUrl;
|
||||
} else {
|
||||
return minioConfig.getEndpoint() + "/" + minioConfig.getBucketName() + "/" + fileUrl;
|
||||
}
|
||||
// 获取当前访问系统的 IP(通过配置或工具方法获取)
|
||||
String currentIp = InetAddress.getLocalHost().getHostAddress();
|
||||
|
||||
// 判断访问来源是内网还是外网
|
||||
boolean isIntranet = currentIp.startsWith("10.");
|
||||
|
||||
// 根据来源返回不同的访问地址
|
||||
String endpoint;
|
||||
if (isIntranet) {
|
||||
// 内网访问,比如你给的 10.145.136.229
|
||||
endpoint = minioConfig.getEndpointInter();
|
||||
} else {
|
||||
// 外网或局域网访问,比如你给的 192.168.20.234
|
||||
endpoint = minioConfig.getEndpoint();
|
||||
}
|
||||
|
||||
// 拼接完整路径(MinIO 地址)
|
||||
return endpoint + "/" + minioConfig.getBucketName() + "/" + fileUrl;
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue