MinIO 响应 img 标签图片请求示例

依赖


    io.minio
    minio
    8.1.0


    commons-io
    commons-io
    2.7

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();
    }
}

前端

MinIO 存储结构

MinIO 响应 img 标签图片请求示例_第1张图片

你可能感兴趣的:(Web,MinIO)