|
@@ -2,8 +2,9 @@ package com.fdkankan.fyun.oss;
|
|
|
|
|
|
import com.aliyun.oss.OSS;
|
|
import com.aliyun.oss.OSS;
|
|
import com.aliyun.oss.model.*;
|
|
import com.aliyun.oss.model.*;
|
|
|
|
+import com.fdkankan.fyun.constant.FYunConstants;
|
|
|
|
+import com.fdkankan.fyun.constant.FYunTypeEnum;
|
|
import com.fdkankan.fyun.face.AbstractFYunFileService;
|
|
import com.fdkankan.fyun.face.AbstractFYunFileService;
|
|
-import com.fdkankan.fyun.oss.constant.OssConstants;
|
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -80,19 +81,32 @@ public class OssFileService extends AbstractFYunFileService {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public String uploadFileByCommand(String bucket, String filePath, String remoteFilePath) {
|
|
public String uploadFileByCommand(String bucket, String filePath, String remoteFilePath) {
|
|
- String ossPath = bucket + "/" + remoteFilePath;
|
|
|
|
try {
|
|
try {
|
|
- String command = String.format(OssConstants.UPLOAD_SH, ossPath, filePath);
|
|
|
|
- log.info("开始上传文件, ossPath:{}, srcPath:{}", ossPath, filePath);
|
|
|
|
|
|
+ String optType = new File(filePath).isDirectory() ? "folder" : "file";
|
|
|
|
+ String command = String.format(FYunConstants.UPLOAD_SH, bucket, filePath, remoteFilePath, FYunTypeEnum.OSS.code(), optType);
|
|
|
|
+ log.info("开始上传文件, ossPath:{}, srcPath:{}", remoteFilePath, filePath);
|
|
callshell(command);
|
|
callshell(command);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- log.error("上传文件失败, ossPath:{}, srcPath:{}", ossPath, filePath);
|
|
|
|
|
|
+ log.error("上传文件失败, ossPath:{}, srcPath:{}", remoteFilePath, filePath);
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
|
+ public void downloadFileByCommand(String bucket, String filePath, String remoteFilePath) {
|
|
|
|
+ try {
|
|
|
|
+ String optType = new File(filePath).isDirectory() ? "folder" : "file";
|
|
|
|
+ String command = String.format(FYunConstants.DOWNLOAD_SH, bucket, filePath, remoteFilePath, FYunTypeEnum.LOCAL.code(), optType);
|
|
|
|
+ log.info("开始上传文件, ossPath:{}, srcPath:{}", remoteFilePath, filePath);
|
|
|
|
+ callshell(command);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error("上传文件失败, ossPath:{}, srcPath:{}", remoteFilePath, filePath);
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
public void deleteFile(String bucket, String remoteFilePath) throws IOException {
|
|
public void deleteFile(String bucket, String remoteFilePath) throws IOException {
|
|
try {
|
|
try {
|
|
ossClient.deleteObject(bucket, remoteFilePath);
|
|
ossClient.deleteObject(bucket, remoteFilePath);
|