首先添加minio的依赖
<dependency>
<groupId>io.minio</groupId>
<artifactId>minio</artifactId>
<version>3.0.10</version>
</dependency>然后写一个controller类
这只是一个简单的demo,没有进行任何的封装,可以根据实际情况进行封装。
企业网站通用源码是以aspcms作为核心进行开发的asp企业网站源码。企业网站通用源码是一套界面设计非常漂亮的企业网站源码,是2016年下半年的又一力作,适合大部分的企业在制作网站是参考或使用,源码亲测完整可用,没有任何功能限制,程序内核使用的是aspcms,如果有不懂的地方或者有不会用的地方可以搜索aspcms的相关技术问题来解决。网站UI虽然不是特别细腻,但是网站整体格调非常立体,尤其是通观全
0
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 = "W2ZWITFFDWFM5TWS3WI9";
private static String secretKey = "dNx++XsRJpjmWVQHWv8djMCFJ0A3YXbEr4qfKHR+";
//上传文件到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 "获取失败";
}
}
}以上就是SpringBoot如何整合minio的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号