feat: 本地上传

新增本地上传功能,上传路径可配置
This commit is contained in:
2023-04-28 09:10:23 +08:00
parent ebd2750533
commit aed4b71395
2 changed files with 41 additions and 29 deletions
@@ -5,6 +5,7 @@ import com.adc.da.report.eo.FileEntity;
import com.adc.da.report.eo.ReportEntity;
import com.adc.da.report.service.IFileService;
import com.adc.da.report.service.IReportService;
import com.adc.da.report.util.LocalFileUtil;
import com.adc.da.report.util.OSSClientUtil;
import com.adc.da.report.util.ObsBootUtil;
import com.adc.da.report.vo.ReportQueryVo;
@@ -63,6 +64,9 @@ public class ReportManageConroller {
@Autowired
private ObsBootUtil obsBootUtil;
@Autowired
private LocalFileUtil localFileUtil;
@Value("${uploadType}")
private String uploadType;
@@ -192,6 +196,7 @@ public class ReportManageConroller {
}
@ApiOperation("testPath")
@GetMapping("/testPath")
@Deprecated
public ResponseMessage testPath() throws URISyntaxException {
HashMap<String, String> pathMap = new HashMap<>();
String jarPath = new File(getClass().getProtectionDomain().getCodeSource().getLocation().toURI().getPath()).getParentFile().getPath();
@@ -201,8 +206,6 @@ public class ReportManageConroller {
return Result.success(pathMap);
}
/**
* 上传文件
* @param file
@@ -236,10 +239,12 @@ public class ReportManageConroller {
try{
String result="";
// 上传方式:阿里云:alioss 华为云:hwobs
if (uploadType.equals("hwobs")){
if ("hwobs".equals(uploadType)){
result = obsBootUtil.upload(file, fileName);
}else if (uploadType.equals("alioss")){
}else if ("alioss".equals(uploadType)) {
result = ossClientUtil.uploadFile2OSS(file.getInputStream(),fileName);
}else if ("local".equals(uploadType)) {
localFileUtil.saveFile(file.getInputStream(), fileName);
}
resultMap.put("key", date + num);
resultMap.put("value", path + "//" + fileName);
@@ -351,10 +356,12 @@ public class ReportManageConroller {
response.setContentType("application/x-download");
// File file = new File(uploadFile, entity.getSavePath());
// 上传方式:阿里云:alioss 华为云:hwobs
if (uploadType.equals("hwobs")){
if ("hwobs".equals(uploadType)){
obsBootUtil.downFile(entity.getSavePath(), response);
}else if (uploadType.equals("alioss")){
}else if ("alioss".equals(uploadType)){
ossClientUtil.downloadFileFromOSS(entity.getSavePath(),response);
}else if ("local".equals(uploadType)){
//do nothing
}
} catch (Exception ex) {