TASK:模块化;
This commit is contained in:
@@ -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();
|
||||||
|
boolean isImage = lowerName.endsWith(".jpg") || lowerName.endsWith(".jpeg") || lowerName.endsWith(".png");
|
||||||
|
|
||||||
|
GetPresignedObjectUrlArgs.Builder builder = GetPresignedObjectUrlArgs.builder()
|
||||||
.bucket(bucketName)
|
.bucket(bucketName)
|
||||||
.object(fileName)
|
.object(fileName)
|
||||||
.expiry(expiry, TimeUnit.MINUTES)
|
.expiry(expiry, TimeUnit.MINUTES)
|
||||||
.method(Method.GET)
|
.method(Method.GET);
|
||||||
.build()
|
|
||||||
);
|
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());
|
||||||
|
|||||||
Reference in New Issue
Block a user