|
@@ -9,6 +9,7 @@ import com.fdkankan.fusion.response.FileInfoVo;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.io.FileUtils;
|
|
import org.apache.commons.io.FileUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.util.ObjectUtils;
|
|
import org.springframework.util.ObjectUtils;
|
|
@@ -25,21 +26,28 @@ import java.util.stream.Collectors;
|
|
public class UploadToOssUtil {
|
|
public class UploadToOssUtil {
|
|
|
|
|
|
|
|
|
|
- @Value("${oss.point:http://oss-cn-shenzhen-internal.aliyuncs.com}")
|
|
|
|
|
|
+ @Value("${oss.point}")
|
|
private String point;
|
|
private String point;
|
|
|
|
|
|
- @Value("${oss.key:LTAIUrvuHqj8pvry}")
|
|
|
|
|
|
+ @Value("${oss.key}")
|
|
private String key;
|
|
private String key;
|
|
|
|
|
|
- @Value("${oss.secrey:JLOVl0k8Ke0aaM8nLMMiUAZ3EiiqI4}")
|
|
|
|
|
|
+ @Value("${oss.secrey}")
|
|
private String secrey;
|
|
private String secrey;
|
|
|
|
|
|
@Value("${oss.bucket:4dkankan}")
|
|
@Value("${oss.bucket:4dkankan}")
|
|
private String bucket;
|
|
private String bucket;
|
|
|
|
|
|
|
|
+ @Value("${upload.type:oss}")
|
|
|
|
+ private String type;
|
|
|
|
+
|
|
@Value("${upload.query-path}")
|
|
@Value("${upload.query-path}")
|
|
private String queryPath;
|
|
private String queryPath;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ LocalToOssUtil localToOssUtil;
|
|
|
|
+
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 获取文件内容-阿里云
|
|
* 获取文件内容-阿里云
|
|
* @param objectName
|
|
* @param objectName
|
|
@@ -47,6 +55,9 @@ public class UploadToOssUtil {
|
|
*/
|
|
*/
|
|
public boolean existKey(String objectName){
|
|
public boolean existKey(String objectName){
|
|
//创建oss客户端
|
|
//创建oss客户端
|
|
|
|
+ if("local".equals(type)){
|
|
|
|
+ return localToOssUtil.existKey(objectName);
|
|
|
|
+ }
|
|
OSSClient ossClient = new OSSClient(point, key, secrey);
|
|
OSSClient ossClient = new OSSClient(point, key, secrey);
|
|
// ossObject包含文件所在的存储空间名称、文件名称、文件元信息以及一个输入流。
|
|
// ossObject包含文件所在的存储空间名称、文件名称、文件元信息以及一个输入流。
|
|
try{
|
|
try{
|
|
@@ -69,6 +80,9 @@ public class UploadToOssUtil {
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
public boolean downFormAli(String objectName, String localPath){
|
|
public boolean downFormAli(String objectName, String localPath){
|
|
|
|
+ if("local".equals(type)){
|
|
|
|
+ return localToOssUtil.downFormAli(objectName,localPath);
|
|
|
|
+ }
|
|
OSSClient ossClient = new OSSClient(point, key, secrey);
|
|
OSSClient ossClient = new OSSClient(point, key, secrey);
|
|
try {
|
|
try {
|
|
com.aliyun.oss.model.GetObjectRequest request = new com.aliyun.oss.model.GetObjectRequest(bucket,objectName);
|
|
com.aliyun.oss.model.GetObjectRequest request = new com.aliyun.oss.model.GetObjectRequest(bucket,objectName);
|
|
@@ -91,6 +105,10 @@ public class UploadToOssUtil {
|
|
|
|
|
|
|
|
|
|
public void uploadOss(String filePath, String key1){
|
|
public void uploadOss(String filePath, String key1){
|
|
|
|
+ if("local".equals(type)){
|
|
|
|
+ localToOssUtil.uploadOss(filePath,key1);
|
|
|
|
+ return ;
|
|
|
|
+ }
|
|
OSSClient ossClient = new OSSClient(point, key, secrey);
|
|
OSSClient ossClient = new OSSClient(point, key, secrey);
|
|
try {
|
|
try {
|
|
log.info("upload-to-oss:file-path:{},oss-path:{}",filePath,key1);
|
|
log.info("upload-to-oss:file-path:{},oss-path:{}",filePath,key1);
|
|
@@ -108,6 +126,10 @@ public class UploadToOssUtil {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
public void delete(String objectName){
|
|
public void delete(String objectName){
|
|
|
|
+ if("local".equals(type)){
|
|
|
|
+ localToOssUtil.delete(objectName);
|
|
|
|
+ return ;
|
|
|
|
+ }
|
|
OSSClient ossClient = new OSSClient(point, key, secrey);
|
|
OSSClient ossClient = new OSSClient(point, key, secrey);
|
|
try {
|
|
try {
|
|
ossClient.deleteObject(bucket, objectName);
|
|
ossClient.deleteObject(bucket, objectName);
|
|
@@ -125,6 +147,9 @@ public class UploadToOssUtil {
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
public List<String> listKeysFromAli(String sourcePath) {
|
|
public List<String> listKeysFromAli(String sourcePath) {
|
|
|
|
+ if("local".equals(type)){
|
|
|
|
+ return localToOssUtil.listKeysFromAli(sourcePath);
|
|
|
|
+ }
|
|
List<String> keyList = new ArrayList<>();
|
|
List<String> keyList = new ArrayList<>();
|
|
OSSClient ossClient = new OSSClient(point, key, secrey);
|
|
OSSClient ossClient = new OSSClient(point, key, secrey);
|
|
try {
|
|
try {
|
|
@@ -201,6 +226,10 @@ public class UploadToOssUtil {
|
|
}
|
|
}
|
|
|
|
|
|
public void uploadFileOss(File file) {
|
|
public void uploadFileOss(File file) {
|
|
|
|
+ if("local".equals(type)){
|
|
|
|
+ localToOssUtil.uploadFileOss(file);
|
|
|
|
+ return ;
|
|
|
|
+ }
|
|
if(file.isFile()){
|
|
if(file.isFile()){
|
|
String ossPath = file.getPath();
|
|
String ossPath = file.getPath();
|
|
ossPath = ossPath.replace("/mnt/","");
|
|
ossPath = ossPath.replace("/mnt/","");
|
|
@@ -215,6 +244,11 @@ public class UploadToOssUtil {
|
|
}
|
|
}
|
|
|
|
|
|
public void copyFile( String sourcePath, String targetPath) {
|
|
public void copyFile( String sourcePath, String targetPath) {
|
|
|
|
+ if("local".equals(type)){
|
|
|
|
+ localToOssUtil.copyFile(sourcePath,targetPath);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
OSSClient ossClient = new OSSClient(point, key, secrey);
|
|
OSSClient ossClient = new OSSClient(point, key, secrey);
|
|
|
|
|
|
try {
|
|
try {
|
|
@@ -287,6 +321,9 @@ public class UploadToOssUtil {
|
|
}
|
|
}
|
|
|
|
|
|
public FileInfoVo getFileInfo(String filePath){
|
|
public FileInfoVo getFileInfo(String filePath){
|
|
|
|
+ if("local".equals(type)){
|
|
|
|
+ return localToOssUtil.getFileInfo(filePath);
|
|
|
|
+ }
|
|
OSSClient ossClient = new OSSClient(point, key, secrey);
|
|
OSSClient ossClient = new OSSClient(point, key, secrey);
|
|
try {
|
|
try {
|
|
GetObjectRequest getObjectMetadataRequest = new GetObjectRequest(bucket, filePath);
|
|
GetObjectRequest getObjectMetadataRequest = new GetObjectRequest(bucket, filePath);
|
|
@@ -308,6 +345,9 @@ public class UploadToOssUtil {
|
|
}
|
|
}
|
|
|
|
|
|
public Long getSize(String filePath){
|
|
public Long getSize(String filePath){
|
|
|
|
+ if("local".equals(type)){
|
|
|
|
+ return localToOssUtil.getSize(filePath);
|
|
|
|
+ }
|
|
OSSClient ossClient = new OSSClient(point, key, secrey);
|
|
OSSClient ossClient = new OSSClient(point, key, secrey);
|
|
Long total = 0L;
|
|
Long total = 0L;
|
|
try {
|
|
try {
|