oss 文件操作

This commit is contained in:
Github_lizhw 2025-12-14 21:58:35 +08:00
parent 6e51aaf06f
commit 92e1861ec0
5 changed files with 23 additions and 31 deletions

View File

@ -95,6 +95,13 @@
<version>1.0.5</version>
</dependency>
<!-- 监控-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>

View File

@ -1,21 +1,18 @@
package com.luban.api.controller;
import cn.hutool.core.util.IdUtil;
import com.luban.api.exception.UnifiedException;
import com.luban.api.vo.FileVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.liuxp.minioplus.api.StorageService;
import org.liuxp.minioplus.api.model.vo.FileMetadataInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
* @author WeiHongBin
@ -26,26 +23,12 @@ import java.util.List;
@Slf4j
public class UploadController {
// @Value("${upload-path}") todo 改成公共文件上传下载
public String uploadPath = "data";
@Autowired
private StorageService storageService;
@Operation(summary = "文件上传")
@PostMapping
public List<FileVO> upload(@Validated MultipartFile files) {
String originalFilename = files.getOriginalFilename();
assert originalFilename != null;
String suffix = originalFilename.substring(originalFilename.lastIndexOf(".") + 1);
String key = IdUtil.fastSimpleUUID() + "." + suffix;
try {
files.transferTo(new File(uploadPath + key));
} catch (IOException e) {
throw new UnifiedException("文件上传失败");
}
return new ArrayList<FileVO>() {{
add(new FileVO() {{
setUrl(key);
}});
}};
public FileMetadataInfoVo upload(@Validated MultipartFile files) throws IOException {
return storageService.createFile(files.getOriginalFilename(), true, "1", files.getInputStream());
}
}

View File

@ -75,8 +75,10 @@ mybatis-plus:
idType: ASSIGN_ID
minioplus:
# rustfs 部署地址
backend: http://localhost:9000
backend: http://localhost:19000
# rustfs 存储桶
bucketPrefix: ruoyih5
# 授权key
key: rustfsadmin
key: NvcaRhUKFy3fuQpxs7S9
# 密钥
secret: rustfsadmin
secret: EmyxRXpZba42370A5Oj9YDqUPLCdMiK6WVkSsgoh

View File

@ -78,9 +78,9 @@ services:
# 时区上海
TZ: Asia/Shanghai
# 管理后台用户名
MINIO_ROOT_USER: ruoyi
MINIO_ROOT_USER: admin
# 管理后台密码最小8个字符
MINIO_ROOT_PASSWORD: ruoyi123
MINIO_ROOT_PASSWORD: admin123
# https需要指定域名
#MINIO_SERVER_URL: "https://xxx.com:9000"
#MINIO_BROWSER_REDIRECT_URL: "https://xxx.com:9001"

View File

@ -11,8 +11,8 @@ services:
image: registry.cn-shanghai.aliyuncs.com/study-03/rustfs:latest
container_name: rustfs
ports:
- "19000:9000" # 管理控制台
- "9090:9090" # API服务端口
- "19000:9000" # API服务端口
- "19001:9001" # 管理控制台
volumes:
- rustfs_data_volume:/data
environment: