Backend Development 7 min read

Deploy kkfileviewer Container and Integrate MinIO with Spring Boot

This guide walks through building and running the kkfileviewer Docker container, then shows how to add MinIO to a Spring Boot application with configuration, a client bean, utility methods, and REST endpoints for uploading files and retrieving presigned preview URLs to display in the kkfileviewer UI.

Java Tech Enthusiast
Java Tech Enthusiast
Java Tech Enthusiast
Deploy kkfileviewer Container and Integrate MinIO with Spring Boot

This guide shows how to install the kkfileviewer container, build its Docker image, run it, and then integrate MinIO object storage into a Spring Boot project for file upload and preview.

1. Deploy kkfileviewer Container

1.1 Download

Use the kkfileviewer 4.4.0‑beta source repository:

https://codeup.aliyun.com/6254dee9a923b68581caaf50/kkfileviewer.git

1.2 Build Image

git clone https://codeup.aliyun.com/6254dee9a923b68581caaf50/kkfileviewer.git
cd kkfileviewer
docker build -t kkfileview:v4.4.0 .

1.3 Run Container

docker run -d -p 8012:8012 --name kkfileview kkfileview:v4.4.0

1.4 Test Access

Open http://<your‑ip>:8012 in a browser.

2. Spring Boot Integration with MinIO

2.1 Add Dependency

<dependency>
    <groupId>io.minio</groupId>
    <artifactId>minio</artifactId>
    <version>8.5.11</version>
</dependency>

2.2 Configuration

Configure MinIO properties in application.yml (or application.properties ).

minio:
  endpoint: http://xxxxx:9000
  accessKey: xxxx
  secretKey: xxxxx
  bucketName: test

2.3 MinIO Configuration Bean

package com.sunny.config;

import io.minio.MinioClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MinioConfig {
    @Value("${minio.endpoint}")
    private String endPoint;
    @Value("${minio.accessKey}")
    private String accessKey;
    @Value("${minio.secretKey}")
    private String secretKey;

    @Bean
    protected MinioClient minioClient() {
        return MinioClient.builder()
                .endpoint(endPoint)
                .credentials(accessKey, secretKey)
                .build();
    }
}

2.4 Utility Class

package com.sunny.utils;

import com.sunny.entity.common.ApiResult;
import com.sunny.exception.AppException;
import io.minio.GetPresignedObjectUrlArgs;
import io.minio.MinioClient;
import io.minio.PutObjectArgs;
import io.minio.http.Method;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;

@Component
public class MinioUtils {
    @Value("${minio.bucketName}")
    private String bucketName;

    @Resource
    private MinioClient minioClient;

    public ApiResult uploadFile(MultipartFile file) throws AppException {
        String fileName = System.currentTimeMillis() + file.getOriginalFilename();
        try (InputStream fi = file.getInputStream()) {
            PutObjectArgs args = PutObjectArgs.builder()
                    .bucket(bucketName)
                    .contentType(file.getContentType())
                    .object(fileName)
                    .stream(fi, fi.available(), -1)
                    .build();
            minioClient.putObject(args);
        } catch (Exception e) {
            throw new AppException("File upload failed: " + e.getMessage());
        }
        return ApiResult.ok(fileName);
    }

    public ApiResult getPreviewUrl(String objectName) throws AppException {
        try {
            GetPresignedObjectUrlArgs urlArgs = GetPresignedObjectUrlArgs.builder()
                    .bucket(bucketName)
                    .object(objectName)
                    .method(Method.GET)
                    .build();
            return ApiResult.ok(minioClient.getPresignedObjectUrl(urlArgs));
        } catch (Exception e) {
            throw new AppException("Failed to get preview URL: " + e.getMessage());
        }
    }
}

2.5 Controller

package com.sunny.controller;

import com.sunny.entity.common.ApiResult;
import com.sunny.exception.AppException;
import com.sunny.utils.MinioUtils;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/file")
public class FileOperationController {
    @Resource
    private MinioUtils minioUtils;

    @PostMapping("/upload")
    public ApiResult upload(MultipartFile file) throws AppException {
        return minioUtils.uploadFile(file);
    }

    @GetMapping("/getPreviewUrl")
    public ApiResult getPreviewUrl(String fileName) throws AppException {
        return minioUtils.getPreviewUrl(fileName);
    }
}

3. Testing

3.1 Upload File

Use the /file/upload endpoint to send a multipart file. The response returns the stored file name.

3.2 Get Preview URL

Call /file/getPreviewUrl?fileName=<returned‑name> to obtain a presigned URL.

3.3 File Preview

Paste the obtained URL into the kkfileviewer web UI to preview the uploaded document.

JavaDockerSpring BootFile UploadkkfileviewerMinIO
Java Tech Enthusiast
Written by

Java Tech Enthusiast

Sharing computer programming language knowledge, focusing on Java fundamentals, data structures, related tools, Spring Cloud, IntelliJ IDEA... Book giveaways, red‑packet rewards and other perks await!

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.