TASK:模块化;
This commit is contained in:
@@ -570,6 +570,36 @@ public class MinioUtil {
|
||||
throw new BusinessException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void upload(String url, File file) {
|
||||
try {
|
||||
// 分割桶名和对象路径
|
||||
int firstSlashIndex = url.indexOf("/");
|
||||
if (firstSlashIndex == -1) {
|
||||
throw new IllegalArgumentException("URL 格式不正确,无法解析桶名和对象路径");
|
||||
}
|
||||
String bucketName = url.substring(0, firstSlashIndex);
|
||||
String objectName = url.substring(firstSlashIndex + 1);
|
||||
|
||||
// 读取文件流
|
||||
try (FileInputStream fileInputStream = new FileInputStream(file)) {
|
||||
// 上传到 MinIO
|
||||
minioClient.putObject(
|
||||
PutObjectArgs.builder()
|
||||
.bucket(bucketName)
|
||||
.object(objectName)
|
||||
.stream(fileInputStream, file.length(), -1)
|
||||
.contentType("application/zip")
|
||||
.build()
|
||||
);
|
||||
System.out.println("文件上传成功: " + url);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.err.println("文件上传失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user