minio存储文件方式修改为local存储。

This commit is contained in:
wangzhijiang
2024-03-19 14:34:47 +08:00
parent 4f334b1961
commit f1ab8f1db2
8 changed files with 220 additions and 49 deletions
@@ -1,7 +1,9 @@
package com.jero.modules.oss.controller;
import com.jero.common.constant.CommonConstant;
import com.jero.common.exception.JeroBootException;
import com.jero.common.util.MinioUtil;
import com.jero.modules.oss.entity.OSSFile;
import com.jero.modules.oss.service.IOSSFileService;
import com.jero.modules.oss.util.SplitFileUtils;
import lombok.extern.slf4j.Slf4j;
@@ -15,10 +17,8 @@ import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.*;
import java.util.List;
@Slf4j
@Controller
@@ -28,27 +28,50 @@ public class SplitFileController {
private String filePathCos;
@Autowired
private IOSSFileService ossFileService;
@Value("${jero.uploadType}")
private String uploadType;
@ResponseBody
@GetMapping("/getImage")
public void queryPageList(@RequestParam("fileName") String fileName, HttpServletResponse response, HttpServletRequest request) {
String fileUrl = filePathCos + "/" + fileName;
response.setHeader("Content-Disposition",
"attachment; filename=\"" + SplitFileUtils.encodeFileName(fileName, request) + "\"");
response.setContentType("application/force-download");
if (MinioUtil.doesObjectExist(fileUrl)) {
try (OutputStream os = response.getOutputStream();
InputStream fis = MinioUtil.download(fileUrl)) {
if(CommonConstant.UPLOAD_TYPE_LOCAL.equals(uploadType)){
String fileId = fileName;
OSSFile ossFile = ossFileService.getById(fileId);
String fileUrl = ossFile.getUrl();
File file = new File(fileUrl);
try {
OutputStream os = response.getOutputStream();
FileInputStream fis = new FileInputStream(file);
int len = 0;
while ((len = fis.read()) != -1) {
os.write(len);
}
os.flush();
} catch (FileNotFoundException e) {
}catch (FileNotFoundException e) {
throw new JeroBootException("文件不存在");
} catch (IOException e) {
throw new JeroBootException("文件不存在");
}
} else if (CommonConstant.UPLOAD_TYPE_MINIO.equals(uploadType)) {
String fileUrl = filePathCos + "/" + fileName;
response.setHeader("Content-Disposition",
"attachment; filename=\"" + SplitFileUtils.encodeFileName(fileName, request) + "\"");
response.setContentType("application/force-download");
if (MinioUtil.doesObjectExist(fileUrl)) {
try (OutputStream os = response.getOutputStream();
InputStream fis = MinioUtil.download(fileUrl)) {
int len = 0;
while ((len = fis.read()) != -1) {
os.write(len);
}
os.flush();
} catch (FileNotFoundException e) {
throw new JeroBootException("文件不存在");
} catch (IOException e) {
throw new JeroBootException("文件不存在");
}
}
}
}
@@ -429,4 +429,10 @@ public class SysCategoryServiceImpl extends ServiceImpl<SysCategoryMapper, SysCa
List<SysCategory> list = list(queryWrapper);
return list;
}
public List<SysCategory> getList(){
// List<SysCategory> list = this.list();
List<SysCategory> list = new ArrayList<>();
return list;
}
}