文件上传接口修改
parent
08111ba1c5
commit
2652943aea
|
|
@ -3,6 +3,7 @@ package com.ruoyi.file.controller;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
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.DeleteMapping;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
@ -24,6 +25,7 @@ public class SysFileController
|
||||||
private static final Logger log = LoggerFactory.getLogger(SysFileController.class);
|
private static final Logger log = LoggerFactory.getLogger(SysFileController.class);
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@Qualifier("minioSysFileService")
|
||||||
private ISysFileService sysFileService;
|
private ISysFileService sysFileService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ import com.ruoyi.file.utils.FileUploadUtils;
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
@Primary
|
@Primary
|
||||||
@Service
|
@Service("localSysFileService")
|
||||||
public class LocalSysFileServiceImpl implements ISysFileService
|
public class LocalSysFileServiceImpl implements ISysFileService
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ import io.minio.RemoveObjectArgs;
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service("minioSysFileService")
|
||||||
public class MinioSysFileServiceImpl implements ISysFileService
|
public class MinioSysFileServiceImpl implements ISysFileService
|
||||||
{
|
{
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|
@ -36,11 +36,30 @@ public class MinioSysFileServiceImpl implements ISysFileService
|
||||||
@Override
|
@Override
|
||||||
public String uploadFile(MultipartFile file) throws Exception
|
public String uploadFile(MultipartFile file) throws Exception
|
||||||
{
|
{
|
||||||
InputStream inputStream = null;
|
// InputStream inputStream = null;
|
||||||
try
|
// 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);
|
String fileName = FileUploadUtils.extractFilename(file);
|
||||||
inputStream = file.getInputStream();
|
InputStream inputStream = file.getInputStream();
|
||||||
PutObjectArgs args = PutObjectArgs.builder()
|
PutObjectArgs args = PutObjectArgs.builder()
|
||||||
.bucket(minioConfig.getBucketName())
|
.bucket(minioConfig.getBucketName())
|
||||||
.object(fileName)
|
.object(fileName)
|
||||||
|
|
@ -48,16 +67,8 @@ public class MinioSysFileServiceImpl implements ISysFileService
|
||||||
.contentType(file.getContentType())
|
.contentType(file.getContentType())
|
||||||
.build();
|
.build();
|
||||||
client.putObject(args);
|
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);
|
IoUtils.closeQuietly(inputStream);
|
||||||
}
|
return minioConfig.getUrl() + "/" + minioConfig.getBucketName() + "/" + fileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -14,12 +14,16 @@ spring:
|
||||||
nacos:
|
nacos:
|
||||||
discovery:
|
discovery:
|
||||||
# 服务注册地址
|
# 服务注册地址
|
||||||
server-addr: 127.0.0.1:8848
|
server-addr: 43.136.76.125:8848
|
||||||
|
namespace: 1c8ac19f-8d7a-4008-a291-90b162b37fd5
|
||||||
config:
|
config:
|
||||||
# 配置中心地址
|
# 配置中心地址
|
||||||
server-addr: 127.0.0.1:8848
|
server-addr: 43.136.76.125:8848
|
||||||
|
namespace: 1c8ac19f-8d7a-4008-a291-90b162b37fd5
|
||||||
# 配置文件格式
|
# 配置文件格式
|
||||||
file-extension: yml
|
file-extension: yml
|
||||||
# 共享配置
|
# 共享配置
|
||||||
shared-configs:
|
shared-configs:
|
||||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||||
|
main:
|
||||||
|
web-application-type: reactive
|
||||||
Loading…
Reference in New Issue