TASK:模块化;

This commit is contained in:
shahaibo
2025-04-07 17:12:33 +08:00
parent d1603fbc16
commit 27cd98f0db

View File

@@ -374,14 +374,31 @@ public class MinioUtil {
*/
public String getPreSignedUrl(String bucketName, String fileName, int expiry) {
try {
return minioClient.getPresignedObjectUrl(
GetPresignedObjectUrlArgs.builder()
.bucket(bucketName)
.object(fileName)
.expiry(expiry, TimeUnit.MINUTES)
.method(Method.GET)
.build()
);
String lowerName = fileName.toLowerCase();
boolean isImage = lowerName.endsWith(".jpg") || lowerName.endsWith(".jpeg") || lowerName.endsWith(".png");
GetPresignedObjectUrlArgs.Builder builder = GetPresignedObjectUrlArgs.builder()
.bucket(bucketName)
.object(fileName)
.expiry(expiry, TimeUnit.MINUTES)
.method(Method.GET);
if (isImage) {
// 根据后缀名设置正确的 content-type
String contentType = "image/jpeg";
if (lowerName.endsWith(".png")) {
contentType = "image/png";
}
Map<String, String> queryParams = new HashMap<>();
queryParams.put("response-content-type", contentType);
queryParams.put("response-content-disposition", "inline");
builder.extraQueryParams(queryParams);
}
return minioClient.getPresignedObjectUrl(builder.build());
} catch (MinioException | InvalidKeyException | IOException | NoSuchAlgorithmException e) {
e.printStackTrace();
throw new BusinessException(e.getMessage());