refactor: 创建存储桶调整到初始化方法中

This commit is contained in:
ray
2024-08-15 21:05:19 +08:00
parent 038f9c6054
commit 42d168c527

View File

@@ -39,7 +39,7 @@ import java.time.LocalDateTime;
public class MinioOssService implements OssService { public class MinioOssService implements OssService {
/** /**
* 服务Endpoint(http://localhost:9000) * 服务Endpoint
*/ */
private String endpoint; private String endpoint;
/** /**
@@ -55,7 +55,7 @@ public class MinioOssService implements OssService {
*/ */
private String bucketName; private String bucketName;
/** /**
* 自定义域名(https://oss.youlai.tech) * 自定义域名
*/ */
private String customDomain; private String customDomain;
@@ -68,6 +68,8 @@ public class MinioOssService implements OssService {
.endpoint(endpoint) .endpoint(endpoint)
.credentials(accessKey, secretKey) .credentials(accessKey, secretKey)
.build(); .build();
// 创建存储桶
createBucketIfAbsent(bucketName);
} }
@@ -80,6 +82,8 @@ public class MinioOssService implements OssService {
@Override @Override
public FileInfo uploadFile(MultipartFile file) { public FileInfo uploadFile(MultipartFile file) {
// 生成文件名(日期文件夹) // 生成文件名(日期文件夹)
String suffix = FileUtil.getSuffix(file.getOriginalFilename()); String suffix = FileUtil.getSuffix(file.getOriginalFilename());
String uuid = IdUtil.simpleUUID(); String uuid = IdUtil.simpleUUID();