diff --git a/bnyer-services/bnyer-file/src/main/java/com/bnyer/file/controller/SysFileController.java b/bnyer-services/bnyer-file/src/main/java/com/bnyer/file/controller/SysFileController.java
index 32a0aae..0ffb986 100644
--- a/bnyer-services/bnyer-file/src/main/java/com/bnyer/file/controller/SysFileController.java
+++ b/bnyer-services/bnyer-file/src/main/java/com/bnyer/file/controller/SysFileController.java
@@ -17,13 +17,14 @@ import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
+import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
* 文件请求处理
- *
+ *
* @author ruoyi
*/
@RestController
@@ -68,4 +69,11 @@ public class SysFileController
}
return R.ok(url);
}
-}
\ No newline at end of file
+
+ @PostMapping("/download")
+ @ResponseBody
+ public R download(@RequestParam("fileName") String fileName, HttpServletResponse response) {
+ minioService.download(fileName,response);
+ return R.ok();
+ }
+}
diff --git a/bnyer-services/bnyer-file/src/main/java/com/bnyer/file/service/MinioService.java b/bnyer-services/bnyer-file/src/main/java/com/bnyer/file/service/MinioService.java
index 15c23c3..feac99f 100644
--- a/bnyer-services/bnyer-file/src/main/java/com/bnyer/file/service/MinioService.java
+++ b/bnyer-services/bnyer-file/src/main/java/com/bnyer/file/service/MinioService.java
@@ -2,6 +2,7 @@ package com.bnyer.file.service;
import org.springframework.web.multipart.MultipartFile;
+import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
/**
@@ -28,4 +29,11 @@ public interface MinioService {
* @throws Exception
*/
String uploadFileByThumb(MultipartFile file) throws Exception;
+
+ /**
+ * 下载图片
+ * @param fileName 文件名
+ * @param response 响应
+ */
+ void download(String fileName, HttpServletResponse response);
}
diff --git a/bnyer-services/bnyer-file/src/main/java/com/bnyer/file/service/MinioSysFileServiceImpl.java b/bnyer-services/bnyer-file/src/main/java/com/bnyer/file/service/MinioSysFileServiceImpl.java
index 94021fd..7c5d91a 100644
--- a/bnyer-services/bnyer-file/src/main/java/com/bnyer/file/service/MinioSysFileServiceImpl.java
+++ b/bnyer-services/bnyer-file/src/main/java/com/bnyer/file/service/MinioSysFileServiceImpl.java
@@ -3,7 +3,9 @@ package com.bnyer.file.service;
import com.bnyer.common.core.exception.ServiceException;
import com.bnyer.file.config.MinioConfig;
import com.bnyer.file.utils.ImgUtil;
+import io.minio.ObjectStat;
import net.coobird.thumbnailator.Thumbnails;
+import org.apache.commons.compress.utils.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
@@ -11,12 +13,14 @@ import com.bnyer.file.utils.FileUploadUtils;
import io.minio.MinioClient;
import io.minio.PutObjectArgs;
+import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.InputStream;
+import java.net.URLEncoder;
/**
* Minio 文件存储
- *
+ *
* @author ruoyi
*/
@Service
@@ -30,7 +34,7 @@ public class MinioSysFileServiceImpl implements MinioService
/**
* 本地文件上传接口
- *
+ *
* @param file 上传的文件
* @return 访问地址
* @throws Exception
@@ -69,4 +73,20 @@ public class MinioSysFileServiceImpl implements MinioService
client.putObject(args);
return minioConfig.getUrl() + "/" + minioConfig.getBucketName() + "/" + multipartFile.getName();
}
+
+ @Override
+ public void download(String fileName, HttpServletResponse response) {
+ // 获取对象的元数据
+ try{
+ ObjectStat stat = client.statObject(minioConfig.getBucketName(), fileName);
+ response.setContentType(stat.contentType());
+ response.setCharacterEncoding("UTF-8");
+ response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
+ InputStream is = client.getObject(minioConfig.getBucketName(), fileName);
+ IOUtils.copy(is, response.getOutputStream());
+ is.close();
+ }catch (Exception e){
+ e.printStackTrace();
+ }
+ }
}
diff --git a/pom.xml b/pom.xml
index 4bd5e73..e4e109a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -36,7 +36,7 @@
2.3
1.2.80
0.9.1
- 8.2.2
+ 7.1.0
4.1.2
3.2.2
2.12.2
@@ -163,9 +163,9 @@
-
- commons-collections
- commons-collections
+
+ commons-collections
+ commons-collections
${commons-collections.version}
@@ -287,4 +287,4 @@
-
\ No newline at end of file
+