依赖
<dependency>
<groupId>io.minio</groupId>
<artifactId>minio</artifactId>
<version>8.1.0</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.7</version>
</dependency>
Minio 配置
@Component
public class MinioConfig {
@Bean
public MinioClient minio() {
return MinioClient.builder()
.endpoint("http://localhost:9000/")
.credentials("admin", "admin123")
.build();
}
}
Controller
@Autowired
private MinioClient minioClient;
@GetMapping("/picture")
public void getPicture(HttpServletRequest request, HttpServletResponse response) {
try (InputStream inputStream = minioClient.getObject(GetObjectArgs.builder().bucket("upload").object("u1/2.png").build());
OutputStream outputStream = new BufferedOutputStream(response.getOutputStream());) {
IOUtils.copy(inputStream, outputStream);
} catch (Exception e) {
e.printStackTrace();
}
}
前端
<img src="http://localhost:8080/picture">
MinIO 存储结构