parent
d3f7d0086b
commit
7e0ac25c86
|
@ -60,7 +60,6 @@ public class FileUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void createFile(String filePath, byte[] fileBytes) {
|
public static void createFile(String filePath, byte[] fileBytes) {
|
||||||
validateFileName(filePath);
|
|
||||||
File file = new File(filePath);
|
File file = new File(filePath);
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
file.delete();
|
file.delete();
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package io.metersphere.metadata.repository;
|
package io.metersphere.metadata.repository;
|
||||||
|
|
||||||
|
import io.metersphere.commons.utils.FileUtils;
|
||||||
import io.metersphere.commons.utils.LogUtil;
|
import io.metersphere.commons.utils.LogUtil;
|
||||||
import io.metersphere.config.MinioProperties;
|
import io.metersphere.config.MinioProperties;
|
||||||
import io.metersphere.dto.FileInfoDTO;
|
import io.metersphere.dto.FileInfoDTO;
|
||||||
|
@ -27,6 +28,7 @@ public class MinIOFileRepository implements FileRepository {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String saveFile(MultipartFile file, FileRequest request) throws Exception {
|
public String saveFile(MultipartFile file, FileRequest request) throws Exception {
|
||||||
|
FileUtils.validateFileName(request.getFileName());
|
||||||
String bucket = minioProperties.getBucket();
|
String bucket = minioProperties.getBucket();
|
||||||
String fileName = request.getProjectId() + "/" + request.getFileName();
|
String fileName = request.getProjectId() + "/" + request.getFileName();
|
||||||
minioClient.putObject(PutObjectArgs.builder()
|
minioClient.putObject(PutObjectArgs.builder()
|
||||||
|
@ -40,6 +42,7 @@ public class MinIOFileRepository implements FileRepository {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String saveFile(byte[] bytes, FileRequest request) throws Exception {
|
public String saveFile(byte[] bytes, FileRequest request) throws Exception {
|
||||||
|
FileUtils.validateFileName(request.getFileName());
|
||||||
String bucket = minioProperties.getBucket();
|
String bucket = minioProperties.getBucket();
|
||||||
String fileName = request.getProjectId() + "/" + request.getFileName();
|
String fileName = request.getProjectId() + "/" + request.getFileName();
|
||||||
try (
|
try (
|
||||||
|
@ -49,7 +52,7 @@ public class MinIOFileRepository implements FileRepository {
|
||||||
.bucket(bucket) // 存储桶
|
.bucket(bucket) // 存储桶
|
||||||
.object(fileName) // 文件名
|
.object(fileName) // 文件名
|
||||||
.stream(inputStream, bytes.length, -1) // 文件内容
|
.stream(inputStream, bytes.length, -1) // 文件内容
|
||||||
// .contentType(file.getContentType()) // 文件类型
|
// .contentType(file.getContentType()) // 文件类型
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
return String.format("%s/%s/%s", minioProperties.getEndpoint(), bucket, fileName);
|
return String.format("%s/%s/%s", minioProperties.getEndpoint(), bucket, fileName);
|
||||||
|
|
Loading…
Reference in New Issue