【minio预处理路径接口】

This commit is contained in:
weizhihong 2022-09-30 15:33:55 +08:00
parent 1dd77a87b9
commit 7defb78dfa
4 changed files with 38 additions and 1 deletions

View File

@ -5,6 +5,7 @@ import club.joylink.rtss.services.MinioService;
import club.joylink.rtss.vo.AccountVO; import club.joylink.rtss.vo.AccountVO;
import club.joylink.rtss.vo.client.PageVO; import club.joylink.rtss.vo.client.PageVO;
import club.joylink.rtss.vo.minio.MinioFilePageVO; import club.joylink.rtss.vo.minio.MinioFilePageVO;
import io.minio.http.Method;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -17,6 +18,11 @@ public class MinioController {
@Autowired @Autowired
private MinioService minioService; private MinioService minioService;
@GetMapping("/perSignedUrl")
public String getPerSignedObjectUrl(String directory, String fileName, Method method) {
return minioService.preSignedObjectUrl(directory, fileName, method);
}
@PostMapping("/file/save") @PostMapping("/file/save")
public void saveFile(@RequestAttribute AccountVO user, @RequestBody MinioFileInfo fileInfo) { public void saveFile(@RequestAttribute AccountVO user, @RequestBody MinioFileInfo fileInfo) {
minioService.saveFileInfo(user, fileInfo); minioService.saveFileInfo(user, fileInfo);

View File

@ -5,6 +5,7 @@ import club.joylink.rtss.util.MinioClientUtil;
import club.joylink.rtss.vo.AccountVO; import club.joylink.rtss.vo.AccountVO;
import club.joylink.rtss.vo.client.PageVO; import club.joylink.rtss.vo.client.PageVO;
import club.joylink.rtss.vo.minio.MinioFilePageVO; import club.joylink.rtss.vo.minio.MinioFilePageVO;
import io.minio.http.Method;
public interface MinioService { public interface MinioService {
/** /**
@ -12,6 +13,8 @@ public interface MinioService {
*/ */
MinioClientUtil createMinioClientUtil(String directory); MinioClientUtil createMinioClientUtil(String directory);
String preSignedObjectUrl(String directory, String fileName, Method method);
/** /**
* 前端保存minio上传的文件信息 * 前端保存minio上传的文件信息
*/ */

View File

@ -10,6 +10,7 @@ import club.joylink.rtss.vo.client.PageVO;
import club.joylink.rtss.vo.minio.MinioFilePageVO; import club.joylink.rtss.vo.minio.MinioFilePageVO;
import com.github.pagehelper.Page; import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import io.minio.http.Method;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
@ -38,6 +39,12 @@ public class MinioServiceImpl implements MinioService {
return minioClientUtil; return minioClientUtil;
} }
@Override
public String preSignedObjectUrl(String directory, String fileName, Method method) {
MinioClientUtil minioClientUtil = createMinioClientUtil(directory);
return minioClientUtil.getPreSignedObjectUrl(fileName, method);
}
@Override @Override
public void saveFileInfo(AccountVO user, MinioFileInfo minioFileInfo) { public void saveFileInfo(AccountVO user, MinioFileInfo minioFileInfo) {
minioFileInfo.setCreator(user.getId()); minioFileInfo.setCreator(user.getId());

View File

@ -18,6 +18,8 @@ import java.io.*;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Base64; import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -221,6 +223,25 @@ public class MinioClientUtil {
} }
} }
/**
* 获取预处理连接
*/
public String getPreSignedObjectUrl(String fileName, Method method) {
try {
Map<String, String> reqParams = new HashMap<String, String>();
reqParams.put("response-content-type", "application/json");
return config.getMinioClient().getPresignedObjectUrl(
GetPresignedObjectUrlArgs.builder().method(method)
.bucket(config.getBucket()).object(getSavePath(fileName))
.expiry(60 * 60 * 24)
.extraQueryParams(reqParams)
.build()
);
} catch (Exception e) {
throw new SimulationException(SimulationExceptionType.System_Fault, e);
}
}
private String getSavePath(String fileName) { private String getSavePath(String fileName) {
return FileInfo.getStoragePath(directory, fileName); return FileInfo.getStoragePath(directory, fileName);
} }