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