Browse Source

oss工具改造

dengsixing 2 years ago
parent
commit
feee47e864

+ 6 - 5
4dkankan-utils-fyun/src/main/java/com/fdkankan/fyun/oss/UploadToOssUtil.java

@@ -87,6 +87,8 @@ public class UploadToOssUtil {
 	 */
 	private static final String UPLOAD_SH = "bash /opt/ossutil/upload.sh %s %s";
 
+	public static final String FYUN_UPLOAD = "sudo bash /opt/ossutil/fyun-upload.sh %s %s /%s %s %s";
+
 	//上传的数据是byte[],key是上传后的文件名
 	public void upload(String bucket, byte[] data,String key1) throws IOException{
 		log.info("开始上传文件 源路径:{},目标路径:{},type:{}" , new String(data, "UTF-8"),key1,type);
@@ -125,14 +127,13 @@ public class UploadToOssUtil {
 	 * @param key
 	 */
 	public void uploadBySh(String bucket, String filePath, String key) {
-		String ossPath = bucket + "/" + key;
+		String command = String.format(FYUN_UPLOAD, bucket, filePath, key, type, "file");
 		try {
-			String command = String.format(UploadToOssUtil.UPLOAD_SH, ossPath, filePath);
-			log.info("开始上传文件, ossPath:{}, srcPath:{}", ossPath, filePath);
+			log.info("开始上传文件, ossPath:{}, srcPath:{}", key, filePath);
 			callshell(command);
-			log.info("上传文件完毕, ossPath:{}, srcPath:{}", ossPath, filePath);
+			log.info("上传文件完毕, ossPath:{}, srcPath:{}", key, filePath);
 		} catch(Exception e) {
-			log.error("上传文件失败, ossPath:{}, srcPath:{}", ossPath, filePath);
+			log.error("上传文件失败, ossPath:{}, srcPath:{}", key, filePath);
 			log.error("上传文件失败", e);
 		}
 	}

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

@@ -54,4 +54,10 @@ public class ConstantCmd {
 	// 修改户型图json文件
 	public static final String TRANSLATE_HOUST_FLOOR = "/opt/Robin/JsonRead.out ";
 
+	public static final String FYUN_DOWNLOAD = "sudo bash /opt/ossutil/fyun-download.sh %s /%s %s %s %s";
+
+	public static final String FYUN_UPLOAD = "sudo bash /opt/ossutil/fyun-upload.sh %s %s /%s %s %s";
+
+
+
 }

+ 11 - 2
4dkankan-utils-model/src/main/java/com/fdkankan/model/utils/CreateObjUtil.java

@@ -593,8 +593,17 @@ public class CreateObjUtil {
 		log.info("删除/mnt/data/下的数据完毕:" + command);
 	}
 
-	public static void ossUtilCp(String fileUrl , String path) throws Exception{
-		String command = ConstantCmd.OSS_UTIL_CP + " " + fileUrl + " " + path;
+	/**
+	 *
+	 * @param fyunType oss类型(oss, aws)
+	 * @param bucket oss桶名
+	 * @param fileUrl	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);
 		Long start = System.currentTimeMillis();
 		log.info("开始oss下载文件:" + command);
 		callshell(command);