Skip to content

介绍 ​

通过代码使得minio打破图片的访问限制,

解决方法 ​

获取文件预签名URL,通过带签名的临时访问URL即可下载

  /**
     * 获取文件预签名URL(默认1小时有效)
     */
    public String getPreviewFileUrl(String bucketName, String objectName) throws Exception{
        return getPreviewFileUrl(bucketName, objectName, 3600);
    }

    /**
     * 获取文件预签名URL(临时授权访问,适用于私有桶)
     *
     * @param bucketName 桶名
     * @param objectName 对象键
     * @param expirySeconds 有效期(秒,最大7天)
     * @return 带签名的临时访问URL
     */
    public String getPreviewFileUrl(String bucketName, String objectName, int expirySeconds) throws Exception{
        GetPresignedObjectUrlArgs args = GetPresignedObjectUrlArgs.builder()
                .method(Method.GET)
                .bucket(bucketName).object(objectName)
                .expiry(expirySeconds)
                .build();
        return minioClient.getPresignedObjectUrl(args);
    }

这样就打通了我们minio的图片下载限制。

上次更新于: