利用docker安装minio
[root@rabbitmq docker]# docker search minio
INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED
docker.io docker.io/minio/minio Kubernetes Native, High Performance Object... 426 [OK]
docker.io docker.io/minio/mc Minio Client (mc) provides a modern altern... 22 [OK]
docker.io docker.io/bitnami/minio Bitnami MinIO Docker Image 6
docker.io docker.io/jessestuart/minio Minio server — supports arm (arm32v6, arm3... 5
docker.io docker.io/pixelchrome/minio-arm This Dockerfile installs Minio on your ARM... 5
docker.io docker.io/bitnami/minio-client Bitnami MinIO Client Docker Image 3
docker.io docker.io/opennms/minion Application container runs Minion by OpenN... 3 [OK]
docker.io docker.io/webhippie/minio Docker images for Minio 3 [OK]
docker.io docker.io/minio/console A graphical user interface for MinIO server 2
docker.io docker.io/rook/minio Minio is a high performance distributed ob... 2
docker.io docker.io/azinchen/minio Minio server Docker image. Always up-to-da... 1
docker.io docker.io/rancher/minio-minio 1
docker.io docker.io/teamwork/minio Minio for Teamwork 1
docker.io docker.io/zenithar/minio-server Minio.io Server in Alpine Linux docker 1 [OK]
docker.io docker.io/joepll/minio-exporter Prometheus exporter for Minio server 0
docker.io docker.io/kazesberger/miniomc-postgres this image is used to create postgres dump... 0
docker.io docker.io/keikoproj/minion-manager https://github.com/orkaproj/minion-manager 0
docker.io docker.io/leviy/minio Minio image for development and testing of... 0 [OK]
docker.io docker.io/minio/k8s-operator Minio Operator for k8s https://kubernetes.io/ 0
docker.io docker.io/minio/mint Collection of tests to detect overall corr... 0 [OK]
docker.io docker.io/nerc/minio Minio container for use in the datalab pro... 0 [OK]
docker.io docker.io/opsmx11/minio Minio for Openshift 0 [OK]
docker.io docker.io/rwsdockercf/minio-resource 0
docker.io docker.io/tobilg/minio-dcos minio on DC/OS 0 [OK]
docker.io docker.io/topdockercat/minio-unraid Minio is an Amazon S3 compatible object st... 0 [OK]
[root@rabbitmq docker]# docker pull minio/minio
Using default tag: latest
Trying to pull repository docker.io/minio/minio ...
latest: Pulling from docker.io/minio/minio
a591faa84ab0: Pull complete
76b9354adec6: Pull complete
abce7c4cd488: Pull complete
6e7646798955: Pull complete
d7748edd807e: Pull complete
1e343c4ba2d9: Pull complete
20b13d3de8fb: Pull complete
Digest: sha256:5635a10f2d047230e1565613b09c9ca2dbb612edfb5d70659d4c90e93a5e6cef
Status: Downloaded newer image for docker.io/minio/minio:latest
[root@rabbitmq docker]# docker run -p 9000:9000 --name minio \
> -d --restart=always \
> -e "MINIO_ACCESS_KEY=admin" \
> -e "MINIO_SECRET_KEY=admin123456" \
> -v /home/data:/data \
> -v /home/config:/root/.minio \
> minio/minio server /data
ef4f614e1b39cc56a2cde1db1639d822859bbbfafaee6b26dc010221dbda3a70
[root@rabbitmq docker]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ef4f614e1b39 minio/minio "/usr/bin/docker-e..." 5 seconds ago Up 4 seconds 0.0.0.0:9000->9000/tcp minio
[root@rabbitmq docker]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ef4f614e1b39 minio/minio "/usr/bin/docker-e..." About a minute ago Up About a minute 0.0.0.0:9000->9000/tcp minio
[root@rabbitmq docker]# docker logs ef4f614e1b39
Attempting encryption of all config, IAM users and policies on MinIO backend
Endpoint: http://172.17.0.2:9000 http://127.0.0.1:9000
Browser Access:
http://172.17.0.2:9000 http://127.0.0.1:9000
Object API (Amazon S3 compatible):
Go: https://docs.min.io/docs/golang-client-quickstart-guide
Java: https://docs.min.io/docs/java-client-quickstart-guide
Python: https://docs.min.io/docs/python-client-quickstart-guide
JavaScript: https://docs.min.io/docs/javascript-client-quickstart-guide
.NET: https://docs.min.io/docs/dotnet-client-quickstart-guide
IAM initialization complete
[root@rabbitmq docker]#
安装结束
登陆页面 ip:9000
点击添加按钮,创建桶, 桶的概念就是相当于文件夹大类 一般分为 正式/测试/开发
开始编码 springboot 整合 mimio
加入依赖
io.minio
minio
3.0.10
写个测试类
package com.file.server.controller;
import io.minio.MinioClient;
import org.apache.tomcat.util.http.fileupload.IOUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
@RestController
public class MinioController {
private static String url = "http://127.0.0.1:9000"; //minio服务的IP端口
private static String accessKey = "W2ZWITFFD*********";
private static String secretKey = "dNx++XsRJpjmW******************";
//上传文件到minio服务
@PostMapping("upload")
public String upload(@RequestParam("fileName") MultipartFile file ) {
try {
MinioClient minioClient = new MinioClient(url, accessKey, secretKey);
InputStream is= file.getInputStream(); //得到文件流
String fileName = file.getOriginalFilename(); //文件名
String contentType = file.getContentType(); //类型
minioClient.putObject("file",fileName,is,contentType); //把文件放置Minio桶(文件夹)
return "上传成功";
}catch (Exception e){
return "上传失败";
}
}
//下载minio服务的文件
@GetMapping("download")
public String download(HttpServletResponse response){
try {
MinioClient minioClient = new MinioClient(url, accessKey, secretKey);
InputStream fileInputStream = minioClient.getObject("file", "test.jpg");
response.setHeader("Content-Disposition", "attachment;filename=" + "test.jpg");
response.setContentType("application/force-download");
response.setCharacterEncoding("UTF-8");
IOUtils.copy(fileInputStream,response.getOutputStream());
return "下载完成";
}catch (Exception e){
return "下载失败";
}
}
//获取minio文件的下载地址
@GetMapping("url")
public String getUrl(){
try {
MinioClient minioClient = new MinioClient(url, accessKey, secretKey);
String url = minioClient.presignedGetObject("file", "test.jpg");
return url;
}catch (Exception e){
return "获取失败";
}
}
}
/**
* 删除⽂件
*
* @param bucketName bucket名称
* @param objectName ⽂件名称
* @throws Exception https://docs.minio.io/cn/java-client-apireference.html#removeObject
*/
public void removeObject(String bucketName, String objectName) throws Exception {
MinioClient minioClient = new MinioClient(url, accessKey, secretKey);
minioClient.removeObject(bucketName, objectName);
}