Backend Development 23 min read

Guide to Installing and Using MinIO with Spring Boot for Large File Uploads

This tutorial explains MinIO's features, common application scenarios, step‑by‑step CentOS 7 Docker installation, Spring Boot configuration, utility classes for bucket management, file upload/download, presigned URLs, and provides REST endpoints for handling large file uploads in Java backend applications.

Architect's Tech Stack
Architect's Tech Stack
Architect's Tech Stack
Guide to Installing and Using MinIO with Spring Boot for Large File Uploads

MinIO is an open‑source object storage server that offers simple installation, scalability, high availability, security features (SSL/TLS, access control), multi‑language SDKs, and strong community support.

Typical use cases include massive data storage, image/video media storage, cloud‑native applications, data protection and disaster recovery, as well as big‑data, AI and machine‑learning workloads.

CentOS 7 installation using Docker:

Create a target directory, pull the MinIO image, and run the container with ports 9000 and 9090, specifying access and secret keys and mounting a data directory. Adjust firewall rules to allow the ports.

mkdir minio
docker pull minio/minio
docker run -p 9000:9000 -p 9090:9090 --net=host --name minio -d \
  -e "MINIO_ACCESS_KEY=IT@WangHui" -e "MINIO_SECRET_KEY=IT@WangHui" \
  minio/minio server /data --console-address ":9000" -address ":9090"

Spring Boot configuration:

Add the MinIO Java SDK dependencies to pom.xml , then configure server port, multipart limits, and MinIO properties (access‑key, secret‑key, URL, bucket name) in application.yml .

<dependency>
  <groupId>io.minio</groupId>
  <artifactId>minio</artifactId>
  <version>8.5.2</version>
</dependency>
server:
  port: 8080
spring:
  servlet:
    multipart:
      max-file-size: 10MB
      max-request-size: 10MB
  minio:
    access-key: dAMaxkWaXUD1CV1JHbqw
    secret-key: AXt3SD0JFkDENFbMeJKOOQb5wj8KvabZWu33Rs84
    url: http://192.168.18.14:9090
    bucket-name: wanghui

Create a MinioConfig class annotated with @Configuration and @ConfigurationProperties("spring.minio") that builds a MinioClient bean using the configured properties.

package com.xiaohui.config;

import io.minio.MinioClient;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Data
@Configuration
@ConfigurationProperties(prefix = "spring.minio")
public class MinioConfig {
    private String accessKey;
    private String secretKey;
    private String url;
    private String bucketName;

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

Utility class: MinioUtils provides methods to check and create buckets, upload files, generate presigned policies and URLs, and download files with proper exception handling.

public void upload(MultipartFile file, String fileName) {
    try (InputStream in = file.getInputStream()) {
        minioClient.putObject(PutObjectArgs.builder()
                .bucket(configuration.getBucketName())
                .object(fileName)
                .stream(in, file.getSize(), -1)
                .contentType(file.getContentType())
                .build());
    } catch (Exception e) {
        e.printStackTrace();
    }
}

Controller: MinioFileUploadController exposes REST endpoints /api/upload , /api/dowload , and /api/getUrl for uploading, downloading, and retrieving file URLs, returning results wrapped in an AjaxResult object.

@RestController
@RequestMapping("/api")
public class MinioFileUploadController {
    @Autowired
    private MinioUtils minioUtils;

    @GetMapping("/upload")
    public AjaxResult uploadFile(@RequestParam("file") MultipartFile file, String fileName) {
        minioUtils.upload(file, fileName);
        return AjaxResult.success("上传成功");
    }

    @GetMapping("/dowload")
    public ResponseEntity downloadFile(@RequestParam("fileName") String fileName) {
        return minioUtils.download(fileName);
    }

    @GetMapping("/getUrl")
    public AjaxResult getFileUrl(@RequestParam("fileName") String fileName) {
        HashMap
map = new HashMap<>();
        map.put("FileUrl", minioUtils.getFileUrl(fileName));
        return AjaxResult.success(map);
    }
}

The article concludes with functional testing screenshots showing successful large‑file uploads and generated file URLs.

JavaDockerSpringBootMinIOFileUploadObjectStorage
Architect's Tech Stack
Written by

Architect's Tech Stack

Java backend, microservices, distributed systems, containerized programming, and more.

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.