|
@@ -22,6 +22,7 @@ import com.xzl.web.service.KnowledgeFileService;
|
|
import io.minio.*;
|
|
import io.minio.*;
|
|
|
|
|
|
|
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.http.HttpHeaders;
|
|
import org.springframework.http.HttpHeaders;
|
|
import org.springframework.http.MediaType;
|
|
import org.springframework.http.MediaType;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
@@ -30,7 +31,6 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
-import static com.xzl.web.core.config.MinIOConfig.getMinioClient;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* 文件Service业务层处理
|
|
* 文件Service业务层处理
|
|
@@ -44,6 +44,9 @@ public class KnowledgeFileServiceImpl implements KnowledgeFileService {
|
|
private final ISysFileFolderService sysFileFolderService;
|
|
private final ISysFileFolderService sysFileFolderService;
|
|
private final MinioUtil minioUtil;
|
|
private final MinioUtil minioUtil;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private MinioClient minioClient;
|
|
|
|
+
|
|
|
|
|
|
// 手动维护的文件扩展名与 ContentType 映射表
|
|
// 手动维护的文件扩展名与 ContentType 映射表
|
|
private static final Map<String, String> CONTENT_TYPE_MAP = new HashMap<>();
|
|
private static final Map<String, String> CONTENT_TYPE_MAP = new HashMap<>();
|
|
@@ -121,7 +124,7 @@ public class KnowledgeFileServiceImpl implements KnowledgeFileService {
|
|
// 删除MinIO存储桶中的文件
|
|
// 删除MinIO存储桶中的文件
|
|
for (KnowledgeFile file : files) {
|
|
for (KnowledgeFile file : files) {
|
|
try {
|
|
try {
|
|
- MinioClient minioClient = getMinioClient();
|
|
|
|
|
|
+// MinioClient minioClient = getMinioClient();
|
|
minioClient.removeObject(RemoveObjectArgs.builder()
|
|
minioClient.removeObject(RemoveObjectArgs.builder()
|
|
.bucket(BUCKET_NAME)
|
|
.bucket(BUCKET_NAME)
|
|
.object(file.getFilePath())
|
|
.object(file.getFilePath())
|
|
@@ -234,7 +237,7 @@ public class KnowledgeFileServiceImpl implements KnowledgeFileService {
|
|
*/
|
|
*/
|
|
public void uploadFile(String bucketName, String objectName, MultipartFile file, String contentType) {
|
|
public void uploadFile(String bucketName, String objectName, MultipartFile file, String contentType) {
|
|
try {
|
|
try {
|
|
- MinioClient minioClient = getMinioClient();
|
|
|
|
|
|
+// MinioClient minioClient = getMinioClient();
|
|
|
|
|
|
// 检查存储桶是否存在,不存在则创建
|
|
// 检查存储桶是否存在,不存在则创建
|
|
boolean found = minioClient.bucketExists(BucketExistsArgs.builder()
|
|
boolean found = minioClient.bucketExists(BucketExistsArgs.builder()
|
|
@@ -350,7 +353,7 @@ public class KnowledgeFileServiceImpl implements KnowledgeFileService {
|
|
// 记录详细错误日志
|
|
// 记录详细错误日志
|
|
System.err.println("文件下载失败: " + e.getMessage());
|
|
System.err.println("文件下载失败: " + e.getMessage());
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
-
|
|
|
|
|
|
+
|
|
// 提供更友好的错误响应
|
|
// 提供更友好的错误响应
|
|
try {
|
|
try {
|
|
response.reset();
|
|
response.reset();
|