minio使用

article/2025/9/21 10:34:52

一、介绍

开源协议的对象存储服务,轻量,性能强

二、安装

windows版链接: https://pan.baidu.com/s/1vv2p8bZBeZFG9cpIhDLVXQ?pwd=s5dd 提取码: s5dd 

下载后创建minioData文件用于储存文件

创建run.bat脚本,内容如下

# 设置用户名
set MINIO_ROOT_USER=admin
# 设置密码(8位)
set MINIO_ROOT_PASSWORD=12345678
minio.exe server --address :9000 --console-address :9001 D:\devtool\minioData

默认账号密码是minioadmin/minioadmin ,编写bat脚本设置启动账号和密码,设置为admin/12345678

启动命令为minio.exe server D:\devtool\minioData

默认参数分别为指定文件访问端口为9000,指定服务控制台访问地址端口为9001

启动bat脚本 

访问地址127.0.0.1:9001 账号为admin/12345678

 三、操作介绍

1.创建bucket

 2.创建账号获取access-key 和secret-key

记录下两个key,在代码中使用 

 3.图片上传

访问图片的地址为127.0.0.1:9000/test/130253654639.jpg    ip+端口+buckets+图片名称

调用地址时,返回没权限访问的提示,需要将bucket设置为public权限

 测试访问

 四、linux下使用

下载地址链接: https://pan.baidu.com/s/1zUPjLQPhtY5ZjfeRvKp24g?pwd=w2em 提取码: w2em 

 分别创建储存文件和日志文件,后台启动命令, 其他操作和windows一样

nohup /data/minio/minio server /data/minio/data --address 10.6.49.9:9000 --console-address 10.6.49.9:9001 > /data/minio/logs/log.log 2>&1 &

 五、代码中使用

 1.配置信息 

minio:endpoint: http://192.168.16.60:9000accesskey: gzh4Alx3Zm5Eceh2secretKey: W19q1koRHPhTPWTjulY1Wyvr7b3qAwl7bucketName: siping

2.配置类

package com.test.mybatistest.minio;import io.minio.MinioClient;import lombok.Data;import org.springframework.boot.context.properties.ConfigurationProperties;import org.springframework.context.annotation.Bean;import org.springframework.stereotype.Component;/*** minio配置信息*/@Data@Component@ConfigurationProperties(prefix = "minio")public class MinioConfig {/*** 服务器地址*/private String endpoint;/*** 账号*/private String accessKey;/*** 密码*/private String secretKey;/*** 储存桶名称*/private String bucketName;@Beanpublic MinioClient minioClient() {return MinioClient.builder().endpoint(endpoint).credentials(accessKey, secretKey).build();}}

3.测试类

package com.test.mybatistest.controller;import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.github.pagehelper.util.StringUtil;
import com.test.mybatistest.minio.MinioConfig;
import io.minio.MinioClient;
import io.minio.PutObjectArgs;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;import java.io.File;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;@Api(tags = "Minio")
@RestController
@Slf4j
@RequestMapping("/minio")
public class MinioController {@Autowiredprivate MinioClient minioClient;@Autowiredprivate MinioConfig minioConfig;@Value("${minio.bucketName}")private String bucketName;/*** 获取文件后缀** @param fullName* @return*/public static String getFileExtension(String fullName) {if (StringUtil.isEmpty(fullName)) return StringPool.EMPTY;String fileName = new File(fullName).getName();int dotIndex = fileName.lastIndexOf(".");return (dotIndex == -1) ? "" : fileName.substring(dotIndex + 1);}/*** 文件上传** @param file* @return*/@ApiOperation("文件上传-批量")@PostMapping("/upload")public Object upload(@RequestParam(name = "file", required = false) MultipartFile[] file) {if (file == null || file.length == 0) {return "上传文件不能为空";}List<Map<String, Object>> orgfileNameList = new ArrayList<>(file.length);for (MultipartFile multipartFile : file) {//1.名称String orgfileName = multipartFile.getOriginalFilename();String fileName = fileName(orgfileName);String path = minioConfig.getEndpoint() + '/' + bucketName + '/' + fileName;//2.返回信息Map<String, Object> fileMap = new HashMap<>();fileMap.put("orgName", orgfileName);fileMap.put("fileName", fileName);fileMap.put("path", path);orgfileNameList.add(fileMap);//3.文件上传try {InputStream in = multipartFile.getInputStream();minioClient.putObject(PutObjectArgs.builder().bucket(bucketName).object(fileName).stream(in, multipartFile.getSize(), -1).contentType("application/octet-stream").build());in.close();} catch (Exception e) {return "上传失败";}}//4.返回Map<String, Object> data = new HashMap<>();data.put("bucket", bucketName);data.put("fileList", orgfileNameList);return data;}/*** 生成图片名称** @param originalFilename* @return*/public String fileName(String originalFilename) {StringBuffer sb = new StringBuffer();String yyyyMMdd = new SimpleDateFormat("yyyyMMdd").format(new Date());ThreadLocalRandom random = ThreadLocalRandom.current();String uuid = new UUID(random.nextLong(), random.nextLong()).toString().replace(StringPool.DASH, StringPool.EMPTY);sb.append("upload").append("/").append(yyyyMMdd).append("/").append(uuid).append(".").append(getFileExtension(originalFilename));return sb.toString();}
}

4.测试

5.contentType作用

当contentType设置为application/octet-stream时,访问文件默认为下载

Content-Type:用于向接收方说明传输资源的媒体类型,从而让浏览器用指定码表去解码。

在浏览器中上传时,设置header为application/octet-stream时,在浏览器打开图片链接会默认进行下载而不是在浏览器中加载打开文件,所以如果想要文件时直接打开,上传时则不要设置application/octet-stream

可以用multipartFile获取contentType,也可以通过文件类型获取

可以通过文件后缀设置对应的contentType

package com.test.mybatistest.minio;import com.github.pagehelper.util.StringUtil;/*** 获取文件的contentType*/public enum ViewContentType {DEFAULT("default", "application/octet-stream"),JPG("jpg", "image/jpeg"),TIFF("tiff", "image/tiff"),GIF("gif", "image/gif"),JFIF("jfif", "image/jpeg"),PNG("png", "image/png"),TIF("tif", "image/tiff"),ICO("ico", "image/x-icon"),JPEG("jpeg", "image/jpeg"),WBMP("wbmp", "image/vnd.wap.wbmp"),FAX("fax", "image/fax"),NET("net", "image/pnetvue"),JPE("jpe", "image/jpeg"),RP("rp", "image/vnd.rn-realpix"),DOC("doc", "application/msord"),PDF("pdf", "application/pdf");private String prefix;private String type;ViewContentType(String prefix, String type) {this.prefix = prefix;this.type = type;}public static String getContentType(String prefix) {if (StringUtil.isEmpty(prefix)) {return DEFAULT.getType();}prefix = prefix.substring(prefix.lastIndexOf(".") + 1);for (ViewContentType value : ViewContentType.values()) {if (prefix.equalsIgnoreCase(value.getPrefix())) {return value.getType();}}return DEFAULT.getType();}public String getPrefix() {return prefix;}public String getType() {return type;}}

http://chatgpt.dhexx.cn/article/POTEegww.shtml

相关文章

CentOS Minimal 和 NetInstall 版本区别

Index of /centos/7.9.2009/isos/x86_64/ 如图&#xff1a; BinDVD版——就是普通安装版&#xff0c;需安装到计算机硬盘才能用&#xff0c;bin一般都比较大&#xff0c;而且包含大量的常用软件&#xff0c;安装时无需再在线下载&#xff08;大部分情况&#xff09;。 minim…

简易最小化虚拟机安装配置(CentOS-7-Minimal)

文章目录 镜像选择虚拟机安装&#xff08;VMware Workstation&#xff09;虚拟网络配置&#xff08;NAT模式&#xff09;虚拟网卡配置 虚拟机配置静态IP配置及测试系统初始化及库安装停止防火墙 & 关闭防火墙自启动关闭 selinux 防火墙更换镜像源并重建镜像源缓存安装 ifco…

pr双击打开图标没反应,下载ZXPSignLib-minimal.dll替换

微智启今天安装了pr cc2018&#xff0c;双击打开图标无反应 于是又试了Premiere cc2019&#xff0c;还是没反应 桌面还多出一些白色文件图标.crash结尾的 解决方案&#xff1a; 下载ZXPSignLib-minimal.dll文件&#xff0c;微智启软件工作室放到pr安装目录的根目录&#xff…

Minimal Square

文章目录 一、A. Minimal Square总结 一、A. Minimal Square 本题链接&#xff1a;A. Minimal Square 题目&#xff1a; A. Minimal Square time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Find the minimu…

出现minimal bash-like...的问题如何解决?

2021.9.4写下此文&#xff0c;以备查阅。 问题如图&#xff1a; 一般出现这个界面即为引导程序出现问题&#xff0c;根据下面两种情况看待&#xff1a; 卸载双系统之一&#xff08;比如之前是windeepin双系统&#xff0c;现在卸载了deepin系统&#xff09;重启时出现。安装新…

Centos教程,DVD、Everything、Minimal、NetInstall区别

今天给大家讲述一下在官网下载Linux中Centos7的时候遇到的版本问题。首先给大家简述一下Centos下载流程。 1.百度搜索Centos&#xff0c;点击官网。 2.点击Download&#xff0c;选择Centos7&#xff08;举例&#xff09;。 3.然后这里我们选择aliyun下载。 4.选择第一个镜像版本…

【已解决】grub引导项修复:Minimal BASH-like line editing is supported.

目录 1 问题背景2 问题探索3 问题解决4 告别Bug 1 问题背景 环境&#xff1a; Win10Ubuntu20.04 现象&#xff1a;双系统电脑向移动硬盘安装Ubuntu系统后&#xff0c;重启黑屏并显示Minimal BASH-like line editing is supported. For the first word, TAB lists possible comm…

Centos7 Minimal 版本基本配置记录

每次搭测试环境之前都需要先装一台干净的虚拟机&#xff0c;然而 Centos7 Minimal 版本快速装完之后还需要配置&#xff1a;网络、国内源、一些基础工具&#xff08;net-tools、vim&#xff09;等才能远程连接和使用。记录一下&#xff0c;方便下次快速配置使用。 目录 1、网…

详解Minimal Web API的使用

一、简介 “Minimal API 是为了创建具有最小依赖关系的 HTTP API”&#xff0c;这是官方的解释。什么意思呢&#xff0c;创建一个 API 并不需要加载许多的依赖。平时在开发 ASP.NET Core Web API 时&#xff0c;通常需要创建 Controller 来定义我们的 API 这种方式&#xff0c…

实例分割------Yolact-minimal结构详解

yolact结构图 网络backbone可以采用resnet101,resnet50甚至vgg16等。然后有3个分支,1个分支输出目标位置,1个分支输出mask系数,1个分类的置信率,所以决定目标的有4(位置)+k(mask系数)+c(分类置信率)个参数。 检测的大致步骤为: 1.从backbone中取出C3,C4,C5; 2.通…

VMware16安装CentOS 7.9操作系统(Minimal版)

记录&#xff1a;299 场景&#xff1a;使用VMware16安装CentOS 7.9操作系统。 基础环境&#xff1a; 虚拟机&#xff1a;VMware16 操作系统&#xff1a;CentOS 7.9 镜像包&#xff1a;CentOS-7-x86_64-DVD-2009.iso 镜像下载地址&#xff1a; 阿里地址&#xff1a;https…

ISO文件boot、dvd、minimal的区别

在centos的下载中&#xff0c;有分为boot、dvd、minimal的iso文件&#xff0c;那么他们之间有什么区别呢&#xff1f; boot.iso 这个版本大小不会超过1G ,只有最基本的启动引导等内容&#xff0c;各类包均需从线上下载&#xff0c;需要快速安装且有可靠网络的前提下&#xff0c…

【minimal problem】资料整理

minimal problem use as few data as to generate a system of algebraic equaIons with a finite number of soluIons 使用尽可能少的数据来生成代数系统 解数有限的方程 以往工作 基于神经网络解一元高次方程 代码实战&#xff1a;解低次方程 代码实战&#xff1a;解高次方…

自我总结:Centos7-Minimal安装后应该干什么

首先我是只小菜鸟&#xff0c;还不是很熟练&#xff0c;我也是弄了N次之后才开始慢慢总结这么一点经验 刚安装完成 ifconfig 和yum命令是不能用的&#xff0c;需要修改配置文件 我是直接将其设置为静态IP 首先点“编辑”-“虚拟机网络编辑器”-“VMnet8”,把下面的东西取消…

手把手教你centos minimal如何安装图形界面!

网上对于centos minimal安装图形界面的介绍五花八门&#xff0c;每个人遇到的情况都不一样&#xff0c;不能一味跟着别人的介绍来往下走&#xff0c;不过多看几篇博文视频&#xff0c;多踩踩坑涨涨经验才知道到底哪种解决方案才是最适用于自己的情况的&#xff0c;也是好事一桩…

安装CentOS7 Minimal后,如何安装可视化图形界面?

安装CentOS7 Minimal后&#xff0c;如何安装可视化图形界面&#xff1f; 附&#xff1a;Centos7各版本的阿里云镜像下载地址&#xff1a;http://mirrors.aliyun.com/centos/7.9.2009/isos/x86_64/ 建议下载everything版本&#xff0c;安装时功能选择项较为全面&#xff0c;本文…

二手笔记本中常见三叉插头以及英标欧标和美标的区别!

本文转载至&#xff1a;http://www.litaow.com/yingjian/2013/0616/1042.html 一些原装笔记本电脑中带的插头看起来都有点不一样&#xff0c;就如图中同一款的T420机型在不同的国家地区发售出现的插头不同&#xff0c;主要的原因还是国家和地区的不一样使用的这种插头标准是有区…

计算机改显存会有啥影响,显卡显存越大越好吗?显存对电脑速度的影响有哪些?...

对于刚接触DIY领域的小白玩家来说,衡量显卡性能的指标就是GPU芯片和其频率,这也确实是显卡性能的决定性因素。但除了GPU,还有一个对显卡性能影响较大的部分,那就是显存。 显卡显存越大越好吗?显存对电脑速度的影响 显存有很多指标:类型、容量、带宽、位宽、速率等,这些指…

联想小新Pro 13新款笔记本电脑获TUV莱茵低蓝光认证

9月23日晚&#xff0c;联想集团在北京全球总部举行新款笔记本电脑小新Pro 13发布会&#xff0c;这也是联想全球首款通过权威第三方机构德国莱茵TUV&#xff08;以下简称“TUV莱茵”&#xff09;低蓝光认证的笔记本电脑&#xff0c;在低蓝光模式下&#xff0c;有害蓝光的比例会下…

LCD养生之道 液晶显示器清洁保养技巧

液晶清洁保养技巧--前言 在液晶显示器已经全面取代CRT成为主流显示器的今天&#xff0c;很多新老用户在显示器升级换代之时无疑都会选择LCD显示器&#xff0c;拥有LCD显示器的朋友也越来越多了&#xff0c;可以说现在是个液晶时代。 LCD显示器的确要比CRT显示器具有很多优势&am…