浏览代码

oss工具改造

dengsixing 2 年之前
父节点
当前提交
da5c5871f4

+ 0 - 6
4dkankan-utils-model/src/main/java/com/fdkankan/model/constants/ConstantCmd.java

@@ -58,10 +58,4 @@ public class ConstantCmd {
 
 	public static final String FYUN_UPLOAD = "sudo bash /opt/ossutil/fyun-upload.sh %s %s /%s %s %s";
 
-
-
-
-	// 上传文件夹
-	public static final String OSS_UTIL_CP_FOLDER ="bash /opt/ossutil/upload.sh %s %s";
-
 }

+ 22 - 16
4dkankan-utils-model/src/main/java/com/fdkankan/model/utils/CreateObjUtil.java

@@ -594,22 +594,39 @@ public class CreateObjUtil {
 	}
 
 	/**
-	 *
+	 * oss文件下载,支持目录或者单个文件下载
 	 * @param fyunType oss类型(oss, aws)
 	 * @param bucket oss桶名
-	 * @param fileUrl	key
+	 * @param remoteFilePath	key
 	 * @param path		本地路径
 	 * @throws Exception
 	 */
-	public static void ossUtilCp(String fyunType, String bucket, String fileUrl , String path) throws Exception{
-		String optType = fileUrl.contains(".") ? "file" : "folder";
-		String command = String.format(ConstantCmd.FYUN_DOWNLOAD, bucket, fileUrl, path, fyunType, optType);
+	public static void ossUtilCp(String fyunType, String bucket, String remoteFilePath , String path) throws Exception{
+		String optType = remoteFilePath.contains(".") ? "file" : "folder";
+		String command = String.format(ConstantCmd.FYUN_DOWNLOAD, bucket, remoteFilePath, path, fyunType, optType);
 		Long start = System.currentTimeMillis();
 		log.info("开始oss下载文件:" + command);
 		callshell(command);
 		log.info("oss下载文件完成,时间为:" + (System.currentTimeMillis() - start));
 	}
 
+	/**
+	 * oss文件上传,支持目录或者单个文件上传
+	 * @param fyunType oss类型(oss, aws)
+	 * @param bucket oss桶名
+	 * @param remoteFilePath	key
+	 * @param path		本地路径
+	 * @throws Exception
+	 */
+	public static void ossUploadUtil(String fyunType, String bucket, String remoteFilePath , String path) throws Exception{
+		String optType = remoteFilePath.contains(".") ? "file" : "folder";
+		String command = String.format(ConstantCmd.FYUN_UPLOAD, bucket, path, remoteFilePath, fyunType, optType);
+		Long start = System.currentTimeMillis();
+		log.info("开始oss上传文件:" + command);
+		callshell(command);
+		log.info("oss上传文件完成,时间为:" + (System.currentTimeMillis() - start));
+	}
+
 	public static void ossFileCp(String fileUrl , String path) throws Exception{
 		String command = ConstantCmd.OSS_FILE_CP + " " + fileUrl + " " + path;
 		Long start = System.currentTimeMillis();
@@ -631,15 +648,4 @@ public class CreateObjUtil {
 		log.info("matterpro获取阿里云图片方法完成,时间为:" + (System.currentTimeMillis() - start));
 	}
 
-	public static void ossUtilCpFolder(String sourceFolder , String targetFolder){
-		File sourceFile = new File(sourceFolder);
-		if (!sourceFile.exists()) {
-			log.error("oss文件夹上传异常,文件夹不存在{}", sourceFolder);
-		}
-		String command = String.format(ConstantCmd.OSS_UTIL_CP_FOLDER,targetFolder,sourceFolder);
-		Long start = System.currentTimeMillis();
-		log.info("开始上传oss文件夹:" + command);
-		callshell(command);
-		log.info("oss文件夹上传完成,时间为:" + (System.currentTimeMillis() - start));
-	}
 }