|
@@ -1,12 +1,14 @@
|
|
|
package com.fdkankan.fyun.oss;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
-import cn.hutool.core.collection.ListUtil;
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
-import cn.hutool.core.util.StrUtil;
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
-import com.aliyun.oss.OSS;
|
|
|
import com.aliyun.oss.OSSClient;
|
|
|
+import com.aliyun.oss.model.DeleteObjectsRequest;
|
|
|
+import com.aliyun.oss.model.DeleteObjectsResult;
|
|
|
+import com.aliyun.oss.model.ListObjectsRequest;
|
|
|
+import com.aliyun.oss.model.ObjectListing;
|
|
|
+import com.aliyun.oss.model.ObjectMetadata;
|
|
|
+import com.aliyun.oss.model.PutObjectResult;
|
|
|
import com.aliyun.oss.model.*;
|
|
|
import com.amazonaws.HttpMethod;
|
|
|
import com.amazonaws.auth.AWSStaticCredentialsProvider;
|
|
@@ -19,22 +21,18 @@ import com.amazonaws.services.s3.model.DeleteObjectsRequest.KeyVersion;
|
|
|
import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest;
|
|
|
import com.amazonaws.services.s3.model.GetObjectRequest;
|
|
|
import com.amazonaws.services.s3.model.PutObjectRequest;
|
|
|
-import com.amazonaws.services.s3.model.S3Object;
|
|
|
-import com.amazonaws.services.s3.model.S3ObjectInputStream;
|
|
|
-import com.amazonaws.services.s3.model.S3ObjectSummary;
|
|
|
+import com.amazonaws.services.s3.model.*;
|
|
|
import com.fdkankan.common.util.CreateObjUtil;
|
|
|
import com.fdkankan.fyun.constant.StorageType;
|
|
|
import com.qiniu.common.Zone;
|
|
|
import com.qiniu.storage.Configuration;
|
|
|
import com.qiniu.storage.UploadManager;
|
|
|
-import java.net.URLDecoder;
|
|
|
-import java.util.function.Consumer;
|
|
|
-import java.util.stream.Collectors;
|
|
|
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.ObjectUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Component;
|
|
@@ -45,10 +43,12 @@ import java.io.*;
|
|
|
import java.net.FileNameMap;
|
|
|
import java.net.URL;
|
|
|
import java.net.URLConnection;
|
|
|
+import java.net.URLDecoder;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Slf4j
|
|
|
@Component
|
|
@@ -128,6 +128,22 @@ public class UploadToOssUtil {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public void uploadFileWithHeaders(String filePath, String key1,Map<String,String> headers) {
|
|
|
+ log.info("开始上传文件 源路径:{},目标路径:{},type:{}" , filePath,key1,type);
|
|
|
+ StorageType storageType = StorageType.get(type);
|
|
|
+ switch (storageType){
|
|
|
+ case OSS:
|
|
|
+ uploadOssWithHeaders(filePath,key1,headers);
|
|
|
+ break;
|
|
|
+ case AWS:
|
|
|
+ uploadAwsWithHeaders(filePath,key1,headers);
|
|
|
+ break;
|
|
|
+ case LOCAL:
|
|
|
+ uploadLocal(filePath,key1);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 通过脚本上传
|
|
|
* @param filePath
|
|
@@ -355,6 +371,10 @@ public class UploadToOssUtil {
|
|
|
|
|
|
|
|
|
public void uploadOss(String filePath, String key1){
|
|
|
+ uploadOssWithHeaders(filePath,key1,null);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void uploadOssWithHeaders(String filePath, String key1,Map<String,String> headers){
|
|
|
OSSClient ossClient = new OSSClient(point, key, secrey);
|
|
|
try {
|
|
|
File file = new File(filePath);
|
|
@@ -366,6 +386,11 @@ public class UploadToOssUtil {
|
|
|
if(filePath.contains(".jpg")){
|
|
|
metadata.setContentType("image/jpeg");
|
|
|
}
|
|
|
+ if(ObjectUtils.isNotEmpty(headers)){
|
|
|
+ for (Map.Entry<String, String> header : headers.entrySet()) {
|
|
|
+ metadata.setHeader(header.getKey(),header.getValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
ossClient.putObject(bucket, key1, new File(filePath), metadata);
|
|
|
|
|
|
} catch (Exception e) {
|
|
@@ -376,6 +401,10 @@ public class UploadToOssUtil {
|
|
|
}
|
|
|
|
|
|
public void uploadAws(String filePath, String key1){
|
|
|
+ uploadAwsWithHeaders(filePath,key1,null);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void uploadAwsWithHeaders(String filePath, String key1,Map<String,String> headers){
|
|
|
try{
|
|
|
uploadS3File(filePath, key1);
|
|
|
}catch (Exception e){
|