浏览代码

upload 配置文件

lyhzzz 3 年之前
父节点
当前提交
7fc43edc5e
共有 1 个文件被更改,包括 24 次插入20 次删除
  1. 24 20
      4dkankan-utils-fyun/src/main/java/com/fdkankan/fyun/oss/UploadToOssUtil.java

+ 24 - 20
4dkankan-utils-fyun/src/main/java/com/fdkankan/fyun/oss/UploadToOssUtil.java

@@ -1,6 +1,7 @@
 package com.fdkankan.fyun.oss;
 
 import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.io.FileUtil;
 import com.aliyun.oss.OSSClient;
 import com.aliyun.oss.model.*;
 import com.amazonaws.HttpMethod;
@@ -20,6 +21,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.fileupload.FileItem;
 import org.apache.commons.fileupload.FileItemFactory;
 import org.apache.commons.fileupload.disk.DiskFileItemFactory;
+import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
@@ -76,15 +78,23 @@ public class UploadToOssUtil {
 
 
 	public void delete(String key1) throws IOException{
-		OSSClient ossClient = new OSSClient(point, key, secrey);
-		try {
-			// bucketMgr.delete(bucketname, key);
-
-			// 2019-2-28 启动aliyun oss 空间
-			ossClient.deleteObject(bucket, key1);
-		} catch (Exception e) {
-			e.printStackTrace();
+		if("oss".equals(type)){
+			OSSClient ossClient = new OSSClient(point, key, secrey);
+			try {
+				// bucketMgr.delete(bucketname, key);
+				// 2019-2-28 启动aliyun oss 空间
+				ossClient.deleteObject(bucket, key1);
+			} catch (Exception e) {
+				e.printStackTrace();
+			}
+		}
+		if("aws".equals(type)){
+			deleteS3Object(key1);
+		}
+		if("local".equals(type)){
+			FileUtil.del(key1);
 		}
+
 	}
 
 	//上传的数据是byte[],key是上传后的文件名
@@ -134,11 +144,9 @@ public class UploadToOssUtil {
 		}
 		if("local".equals(type)){
 			try {
+				File srcFile = new File(filePath);
 				File file = new File(localPath + key1);
-				if (!file.getParentFile().exists()) {
-					file.getParentFile().mkdirs();
-				}
-				file.createNewFile();
+				FileUtils.copyFile(srcFile,file);
 			}catch (Exception e){
 				e.printStackTrace();
 			}
@@ -182,11 +190,9 @@ public class UploadToOssUtil {
 		}
 		if("local".equals(type)){
 			try {
+				File srcFile = new File(filePath);
 				File file = new File(localPath + key1);
-				if (!file.getParentFile().exists()) {
-					file.getParentFile().mkdirs();
-				}
-				file.createNewFile();
+				FileUtils.copyFile(srcFile,file);
 			}catch (Exception e){
 				e.printStackTrace();
 			}
@@ -230,11 +236,9 @@ public class UploadToOssUtil {
 
 		if("local".equals(type)){
 			try {
+				File srcFile = new File(filePath);
 				File file = new File(localPath + key1);
-				if (!file.getParentFile().exists()) {
-					file.getParentFile().mkdirs();
-				}
-				file.createNewFile();
+				FileUtils.copyFile(srcFile,file);
 			}catch (Exception e){
 				e.printStackTrace();
 			}