文件上传接口修改

pull/440/head
CHENYUQING 2025-11-28 17:04:43 +08:00
parent 08111ba1c5
commit 2652943aea
4 changed files with 43 additions and 26 deletions

View File

@ -3,6 +3,7 @@ package com.ruoyi.file.controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
@ -24,6 +25,7 @@ public class SysFileController
private static final Logger log = LoggerFactory.getLogger(SysFileController.class);
@Autowired
@Qualifier("minioSysFileService")
private ISysFileService sysFileService;
/**

View File

@ -14,7 +14,7 @@ import com.ruoyi.file.utils.FileUploadUtils;
* @author ruoyi
*/
@Primary
@Service
@Service("localSysFileService")
public class LocalSysFileServiceImpl implements ISysFileService
{
/**

View File

@ -17,7 +17,7 @@ import io.minio.RemoveObjectArgs;
*
* @author ruoyi
*/
@Service
@Service("minioSysFileService")
public class MinioSysFileServiceImpl implements ISysFileService
{
@Autowired
@ -36,11 +36,30 @@ public class MinioSysFileServiceImpl implements ISysFileService
@Override
public String uploadFile(MultipartFile file) throws Exception
{
InputStream inputStream = null;
try
{
// InputStream inputStream = null;
// try
// {
// String fileName = FileUploadUtils.extractFilename(file);
// inputStream = file.getInputStream();
// PutObjectArgs args = PutObjectArgs.builder()
// .bucket(minioConfig.getBucketName())
// .object(fileName)
// .stream(inputStream, file.getSize(), -1)
// .contentType(file.getContentType())
// .build();
// client.putObject(args);
// return minioConfig.getUrl() + "/" + minioConfig.getBucketName() + "/" + fileName;
// }
// catch (Exception e)
// {
// throw new RuntimeException("Minio Failed to upload file", e);
// }
// finally
// {
// IoUtils.closeQuietly(inputStream);
// }
String fileName = FileUploadUtils.extractFilename(file);
inputStream = file.getInputStream();
InputStream inputStream = file.getInputStream();
PutObjectArgs args = PutObjectArgs.builder()
.bucket(minioConfig.getBucketName())
.object(fileName)
@ -48,16 +67,8 @@ public class MinioSysFileServiceImpl implements ISysFileService
.contentType(file.getContentType())
.build();
client.putObject(args);
return minioConfig.getUrl() + "/" + minioConfig.getBucketName() + "/" + fileName;
}
catch (Exception e)
{
throw new RuntimeException("Minio Failed to upload file", e);
}
finally
{
IoUtils.closeQuietly(inputStream);
}
return minioConfig.getUrl() + "/" + minioConfig.getBucketName() + "/" + fileName;
}
/**

View File

@ -14,12 +14,16 @@ spring:
nacos:
discovery:
# 服务注册地址
server-addr: 127.0.0.1:8848
server-addr: 43.136.76.125:8848
namespace: 1c8ac19f-8d7a-4008-a291-90b162b37fd5
config:
# 配置中心地址
server-addr: 127.0.0.1:8848
server-addr: 43.136.76.125:8848
namespace: 1c8ac19f-8d7a-4008-a291-90b162b37fd5
# 配置文件格式
file-extension: yml
# 共享配置
shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
main:
web-application-type: reactive