|
|
@@ -59,6 +59,7 @@ public class FileUtils {
|
|
|
private static String accessKeyId;
|
|
|
private static String accessKeySecret;
|
|
|
private static String bucketName;
|
|
|
+ private static String domain;
|
|
|
private static FileUtils fileUtils;
|
|
|
|
|
|
@Value("${aliyun.oss.endpoint}")
|
|
|
@@ -73,6 +74,8 @@ public class FileUtils {
|
|
|
@Value("${aliyun.oss.bucket}")
|
|
|
public String oss_bucketName;
|
|
|
|
|
|
+ @Value("${common.domain}")
|
|
|
+ private String domainUrl;
|
|
|
private static void defaultOss() {
|
|
|
if (StringUtils.isBlank(endpoint)) {
|
|
|
endpoint = DEFAULT_ENDPOINT;
|
|
|
@@ -94,6 +97,7 @@ public class FileUtils {
|
|
|
accessKeyId = this.oss_accessKeyId;
|
|
|
accessKeySecret = this.oss_accessKeySecret;
|
|
|
bucketName = this.oss_bucketName;
|
|
|
+ domain = this.domainUrl;
|
|
|
}
|
|
|
|
|
|
// @PostConstruct
|
|
|
@@ -134,13 +138,14 @@ public class FileUtils {
|
|
|
*/
|
|
|
public static String getOSSAddressPrefix() {
|
|
|
defaultOss();
|
|
|
- return StringConstant.HTTPS_STRING
|
|
|
- + StringConstant.COLON
|
|
|
- + StringConstant.LEFT_SEPARATORS
|
|
|
- + bucketName
|
|
|
- + StringConstant.POINT
|
|
|
- + endpoint
|
|
|
- + StringConstant.LEFT_SEPARATOR;
|
|
|
+// return StringConstant.HTTPS_STRING
|
|
|
+// + StringConstant.COLON
|
|
|
+// + StringConstant.LEFT_SEPARATORS
|
|
|
+// + bucketName
|
|
|
+// + StringConstant.POINT
|
|
|
+// + endpoint
|
|
|
+// + StringConstant.LEFT_SEPARATOR;
|
|
|
+ return domain;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -170,7 +175,18 @@ public class FileUtils {
|
|
|
if (StrUtil.startWith(replace, "http")) {
|
|
|
return replace;
|
|
|
}
|
|
|
- return stringBuilder.append(getOSSAddressPrefix()).append(replace).toString();
|
|
|
+ String prefix = getOSSAddressPrefix();
|
|
|
+ String path = replace;
|
|
|
+
|
|
|
+ if (prefix.endsWith("/")) {
|
|
|
+ prefix = prefix.substring(0, prefix.length() - 1);
|
|
|
+ }
|
|
|
+ if (path.startsWith("/")) {
|
|
|
+ path = path.substring(1);
|
|
|
+ }
|
|
|
+
|
|
|
+ stringBuilder.append(prefix).append("/").append(path);
|
|
|
+ return stringBuilder.toString();
|
|
|
}
|
|
|
|
|
|
|