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) { public String getPreSignedUrl(String bucketName, String fileName, int expiry) {
try { try {
return minioClient.getPresignedObjectUrl(
GetPresignedObjectUrlArgs.builder() String lowerName = fileName.toLowerCase();
.bucket(bucketName) boolean isImage = lowerName.endsWith(".jpg") || lowerName.endsWith(".jpeg") || lowerName.endsWith(".png");
.object(fileName)
.expiry(expiry, TimeUnit.MINUTES) GetPresignedObjectUrlArgs.Builder builder = GetPresignedObjectUrlArgs.builder()
.method(Method.GET) .bucket(bucketName)
.build() .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) { } catch (MinioException | InvalidKeyException | IOException | NoSuchAlgorithmException e) {
e.printStackTrace(); e.printStackTrace();
throw new BusinessException(e.getMessage()); throw new BusinessException(e.getMessage());