Ver Fonte

处理上传路径的开头斜杠

xiatian há 5 anos atrás
pai
commit
74d54627e3

+ 10 - 3
src/main/java/cn/com/qmth/examcloud/web/filestorage/impl/AliyunFileStorageImpl.java

@@ -463,9 +463,7 @@ public class AliyunFileStorageImpl implements FileStorage {
 		OSS oss=AliyunSiteManager.getAliYunClientBySiteId(siteId);
 		// 阿里云文件路径
 		String path = FreeMarkerUtil.process(as.getPath(), env);
-		if (path.startsWith("/")) {
-			path = path.substring(1);
-		}
+		path=disposePath(path);
 		oss.putObject(bucket, path, in);
 
 		return path;
@@ -477,4 +475,13 @@ public class AliyunFileStorageImpl implements FileStorage {
 		String path=FileStorageType.ALIYUN.name().toLowerCase()+"-"+yunId+"://"+relativePath;
 		return path;
 	}
+	private  String disposePath(String path) {
+		for(;;) {
+			if(path.startsWith("/")) {
+				path=path.substring(1);
+			}else {
+				return path;
+			}
+		}
+	}
 }

+ 14 - 1
src/main/java/cn/com/qmth/examcloud/web/upyun/UpyunServiceImpl.java

@@ -32,6 +32,7 @@ public class UpyunServiceImpl implements UpyunService {
 		UpYunClient upYunClient = UpyunSiteManager.getUpYunClientByUpyunId(upyunSite.getUpyunId());
 
 		String path = FreeMarkerUtil.process(upyunSite.getPath(), env);
+		path=disposePath(path);
 		UpYunPathInfo pathInfo = upYunClient.writeFile(path, in, md5);
 		return pathInfo;
 	}
@@ -46,6 +47,7 @@ public class UpyunServiceImpl implements UpyunService {
 		UpYunClient upYunClient = UpyunSiteManager.getUpYunClientByUpyunId(upyunSite.getUpyunId());
 
 		String path = FreeMarkerUtil.process(upyunSite.getPath(), env);
+		path=disposePath(path);
 		UpYunPathInfo pathInfo = upYunClient.writeFile(path, file, withMd5);
 		return pathInfo;
 	}
@@ -59,6 +61,7 @@ public class UpyunServiceImpl implements UpyunService {
 		UpYunClient upYunClient = UpyunSiteManager.getUpYunClientByUpyunId(upyunSite.getUpyunId());
 
 		String path = FreeMarkerUtil.process(upyunSite.getPath(), env);
+		path=disposePath(path);
 		UpYunPathInfo pathInfo = upYunClient.writeFile(path, file, md5);
 		return pathInfo;
 	}
@@ -82,6 +85,7 @@ public class UpyunServiceImpl implements UpyunService {
 		UpYunClient upYunClient = UpyunSiteManager.getUpYunClientByUpyunId(upyunSite.getUpyunId());
 
 		String path = FreeMarkerUtil.process(upyunSite.getPath(), env);
+		path=disposePath(path);
 		YunHttpRequest request = upYunClient.buildUpYunHttpRequest(path, md5);
 		return request;
 	}
@@ -93,5 +97,14 @@ public class UpyunServiceImpl implements UpyunService {
 
 		upYunClient.deleteFile(filePath);
 	}
-
+	
+	private  String disposePath(String path) {
+		for(;;) {
+			if(path.startsWith("/")) {
+				path=path.substring(1);
+			}else {
+				return "/"+path;
+			}
+		}
+	}
 }