|
@@ -123,6 +123,9 @@ public class FileStorageUtil {
|
|
* @return 可直接访问的文件地址
|
|
* @return 可直接访问的文件地址
|
|
*/
|
|
*/
|
|
public static String realPath(String path) {
|
|
public static String realPath(String path) {
|
|
|
|
+ if(StringUtils.isBlank(path)) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
|
|
if (StringUtils.isBlank(path)) {
|
|
if (StringUtils.isBlank(path)) {
|
|
throw new StatusException("3001", "文件路径是空");
|
|
throw new StatusException("3001", "文件路径是空");
|
|
@@ -149,6 +152,7 @@ public class FileStorageUtil {
|
|
* @return 转换之后的路径
|
|
* @return 转换之后的路径
|
|
*/
|
|
*/
|
|
public static String transPath(String path, FileStorageType transFsType) {
|
|
public static String transPath(String path, FileStorageType transFsType) {
|
|
|
|
+
|
|
File file = null;
|
|
File file = null;
|
|
if (StringUtils.isBlank(path)) {
|
|
if (StringUtils.isBlank(path)) {
|
|
throw new StatusException("4001", "文件路径是空");
|
|
throw new StatusException("4001", "文件路径是空");
|
|
@@ -203,6 +207,9 @@ public class FileStorageUtil {
|
|
* @return 处理后的路径。补全路径头。
|
|
* @return 处理后的路径。补全路径头。
|
|
*/
|
|
*/
|
|
private static String diposeOldPath(String path) {
|
|
private static String diposeOldPath(String path) {
|
|
|
|
+ if(StringUtils.isBlank(path)) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
// 如果是全路径直接返回
|
|
// 如果是全路径直接返回
|
|
if (path.startsWith("http") || path.startsWith("https")) {
|
|
if (path.startsWith("http") || path.startsWith("https")) {
|
|
return path;
|
|
return path;
|
|
@@ -219,8 +226,13 @@ public class FileStorageUtil {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
public static String getUrl(String domain, String path) {
|
|
public static String getUrl(String domain, String path) {
|
|
|
|
+ if(StringUtils.isBlank(domain)) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ if(StringUtils.isBlank(path)) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
if (path.startsWith("/")) {
|
|
if (path.startsWith("/")) {
|
|
path = path.substring(1);
|
|
path = path.substring(1);
|
|
}
|
|
}
|
|
@@ -295,11 +307,14 @@ public class FileStorageUtil {
|
|
* @return 处理之后的路径
|
|
* @return 处理之后的路径
|
|
*/
|
|
*/
|
|
public static String getIntactPath(String prefixPath,String sourcePath) {
|
|
public static String getIntactPath(String prefixPath,String sourcePath) {
|
|
|
|
+ if(StringUtils.isBlank(sourcePath)) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
// 如果是全路径直接返回
|
|
// 如果是全路径直接返回
|
|
if (sourcePath.startsWith("http") || sourcePath.startsWith("https")) {
|
|
if (sourcePath.startsWith("http") || sourcePath.startsWith("https")) {
|
|
return sourcePath;
|
|
return sourcePath;
|
|
}
|
|
}
|
|
- // 如果是半路径,转换成又拍云类型
|
|
|
|
|
|
+ // 如果是半路径则拼接
|
|
if (sourcePath.indexOf(":") == -1) {
|
|
if (sourcePath.indexOf(":") == -1) {
|
|
if (sourcePath.startsWith("/")) {
|
|
if (sourcePath.startsWith("/")) {
|
|
sourcePath = sourcePath.substring(1);
|
|
sourcePath = sourcePath.substring(1);
|
|
@@ -318,6 +333,9 @@ public class FileStorageUtil {
|
|
* @param path 全路径,包含根目录,含协议名
|
|
* @param path 全路径,包含根目录,含协议名
|
|
*/
|
|
*/
|
|
public static void deleteFile(String path) {
|
|
public static void deleteFile(String path) {
|
|
|
|
+ if(StringUtils.isBlank(path)) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
path=diposeOldPath(path);
|
|
path=diposeOldPath(path);
|
|
// 如果是全路径直接返回
|
|
// 如果是全路径直接返回
|
|
if (path.startsWith("http") || path.startsWith("https")) {
|
|
if (path.startsWith("http") || path.startsWith("https")) {
|
|
@@ -334,7 +352,9 @@ public class FileStorageUtil {
|
|
* @return 可直接访问的文件地址,如果没有配置备用地址,则返回主域名地址
|
|
* @return 可直接访问的文件地址,如果没有配置备用地址,则返回主域名地址
|
|
*/
|
|
*/
|
|
public static String realPathBackup(String path) {
|
|
public static String realPathBackup(String path) {
|
|
-
|
|
|
|
|
|
+ if(StringUtils.isBlank(path)) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
if (StringUtils.isBlank(path)) {
|
|
if (StringUtils.isBlank(path)) {
|
|
throw new StatusException("6001", "文件路径是空");
|
|
throw new StatusException("6001", "文件路径是空");
|
|
}
|
|
}
|
|
@@ -352,6 +372,9 @@ public class FileStorageUtil {
|
|
}
|
|
}
|
|
|
|
|
|
public static String getYunId(String path) {
|
|
public static String getYunId(String path) {
|
|
|
|
+ if(StringUtils.isBlank(path)) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
if(path.indexOf(connector)==-1) {
|
|
if(path.indexOf(connector)==-1) {
|
|
throw new StatusException("7001", "文件路径格式错误:"+path);
|
|
throw new StatusException("7001", "文件路径格式错误:"+path);
|
|
}
|
|
}
|
|
@@ -367,6 +390,9 @@ public class FileStorageUtil {
|
|
}
|
|
}
|
|
|
|
|
|
public static String getHead(String path) {
|
|
public static String getHead(String path) {
|
|
|
|
+ if(StringUtils.isBlank(path)) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
if(path.indexOf(connector)==-1) {
|
|
if(path.indexOf(connector)==-1) {
|
|
throw new StatusException("8001", "文件路径格式错误:"+path);
|
|
throw new StatusException("8001", "文件路径格式错误:"+path);
|
|
}
|
|
}
|
|
@@ -382,6 +408,9 @@ public class FileStorageUtil {
|
|
}
|
|
}
|
|
|
|
|
|
public static String getPath(String path) {
|
|
public static String getPath(String path) {
|
|
|
|
+ if(StringUtils.isBlank(path)) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
if(path.indexOf(connector)==-1) {
|
|
if(path.indexOf(connector)==-1) {
|
|
throw new StatusException("9001", "文件路径格式错误:"+path);
|
|
throw new StatusException("9001", "文件路径格式错误:"+path);
|
|
}
|
|
}
|