当前位置: 首页 > wzjs >正文

企业网站建设比较调查怎么写wordpress ftp免密码破解

企业网站建设比较调查怎么写,wordpress ftp免密码破解,网站建设存在的问题及建议,phpcms网站转移在 ​​Spring Boot​​ 项目中,​​MinIO​​ 通常用于 ​​对象存储​​,类似于 AWS S3,可以存储图片、视频、文档等文件。以下是 ​​MinIO 在 Spring Boot 中的常见使用场景​​ 及 ​​详细使用过程​​。 1. MinIO 在 Spring Boot 中的…

        在 ​​Spring Boot​​ 项目中,​​MinIO​​ 通常用于 ​​对象存储​​,类似于 AWS S3,可以存储图片、视频、文档等文件。以下是 ​​MinIO 在 Spring Boot 中的常见使用场景​​ 及 ​​详细使用过程​​。


1. MinIO 在 Spring Boot 中的常见使用场景​

场景说明
​图片/文件上传​用户上传头像、商品图片、文档等,存储到 MinIO,返回 URL 给前端展示。
​文件下载​从 MinIO 下载文件(如 PDF、视频、图片等)。
​文件管理​删除、更新、查询文件(如按文件名、前缀搜索)。
​静态资源托管​将静态资源(如 HTML、CSS、JS)存储在 MinIO,并通过 CDN 加速访问。
​备份与归档​存储日志、数据库备份等大文件。

2. Spring Boot 整合 MinIO 的详细步骤​

​2.1 准备工作​

  1. ​安装 MinIO​​(本地或云服务器):

    • ​本地 Docker 运行 MinIO​​:
      docker run -p 9000:9000 -p 9001:9001 --name minio \-e "MINIO_ROOT_USER=minioadmin" \-e "MINIO_ROOT_PASSWORD=minioadmin" \quay.io/minio/minio server /data --console-address ":9001"

  

        访问 MinIO 控制台:http://localhost:9001(默认账号 minioadmin / minioadmin)。

  1. ​创建 Bucket​​(存储桶):

    • 在 MinIO 控制台创建一个 Bucket(如 grass-images)。

2.2 Spring Boot 项目集成 MinIO​

​(1) 添加 MinIO Java SDK 依赖​

在 pom.xml 中添加:

<dependency><groupId>io.minio</groupId><artifactId>minio</artifactId><version>8.5.4</version> <!-- 使用最新版本 -->
</dependency>
(2) 配置 MinIO 连接信息​

在 application.yml 或 application.properties 中配置:

minio:endpoint: http://localhost:9000  # MinIO 服务地址access-key: minioadmin           # MinIO 访问密钥secret-key: minioadmin           # MinIO 密钥bucket-name: grass-images        # 默认 Bucket 名称
(3) 创建 MinIO 配置类​
import io.minio.MinioClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;@Configuration
public class MinioConfig {@Value("${minio.endpoint}")private String endpoint;@Value("${minio.access-key}")private String accessKey;@Value("${minio.secret-key}")private String secretKey;@Beanpublic MinioClient minioClient() {return MinioClient.builder().endpoint(endpoint).credentials(accessKey, secretKey).build();}
}
​(4) 创建 MinIO 服务类​
import io.minio.*;
import io.minio.http.Method;
import io.minio.messages.Item;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;@Service
public class MinioService {@Autowiredprivate MinioClient minioClient;@Value("${minio.bucket-name}")private String bucketName;/*** 上传文件到 MinIO*/public String uploadFile(MultipartFile file, String objectName) throws Exception {// 检查 Bucket 是否存在,不存在则创建boolean isExist = minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build());if (!isExist) {minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build());}// 上传文件minioClient.putObject(PutObjectArgs.builder().bucket(bucketName).object(objectName).stream(file.getInputStream(), file.getSize(), -1).contentType(file.getContentType()).build());// 返回文件访问 URLreturn getFileUrl(objectName);}/*** 获取文件 URL(可设置过期时间)*/public String getFileUrl(String objectName) {// 生成预签名 URL(默认 7 天过期)GetPresignedObjectUrlArgs args = GetPresignedObjectUrlArgs.builder().method(Method.GET).bucket(bucketName).object(objectName).expiry(7, java.util.concurrent.TimeUnit.DAYS).build();try {return minioClient.getPresignedObjectUrl(args);} catch (Exception e) {throw new RuntimeException("获取文件 URL 失败", e);}}/*** 删除文件*/public void deleteFile(String objectName) throws Exception {minioClient.removeObject(RemoveObjectArgs.builder().bucket(bucketName).object(objectName).build());}/*** 获取 Bucket 下所有文件*/public List<Map<String, String>> listFiles() throws Exception {List<Map<String, String>> fileList = new ArrayList<>();Iterable<Result<Item>> results = minioClient.listObjects(ListObjectsArgs.builder().bucket(bucketName).recursive(true).build());for (Result<Item> result : results) {Item item = result.get();Map<String, String> fileMap = new HashMap<>();fileMap.put("name", item.objectName());fileList.add(fileMap);}return fileList;}
}
(5) 创建 Controller 接口​
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;import java.util.List;
import java.util.Map;@RestController
@RequestMapping("/api/minio")
public class MinioController {@Autowiredprivate MinioService minioService;/*** 上传文件*/@PostMapping("/upload")public Map<String, String> uploadFile(@RequestParam("file") MultipartFile file) {try {String objectName = System.currentTimeMillis() + "_" + file.getOriginalFilename();String fileUrl = minioService.uploadFile(file, objectName);return Map.of("url", fileUrl);} catch (Exception e) {throw new RuntimeException("文件上传失败", e);}}/*** 获取文件 URL*/@GetMapping("/url/{objectName}")public Map<String, String> getFileUrl(@PathVariable String objectName) {String url = minioService.getFileUrl(objectName);return Map.of("url", url);}/*** 删除文件*/@DeleteMapping("/delete/{objectName}")public Map<String, String> deleteFile(@PathVariable String objectName) {try {minioService.deleteFile(objectName);return Map.of("message", "文件删除成功");} catch (Exception e) {throw new RuntimeException("文件删除失败", e);}}/*** 获取所有文件*/@GetMapping("/list")public List<Map<String, String>> listFiles() {try {return minioService.listFiles();} catch (Exception e) {throw new RuntimeException("获取文件列表失败", e);}}
}

2.3 测试 MinIO 文件上传​

  1. ​前端调用上传接口​​(如 POST /api/minio/upload):

    const formData = new FormData();
    formData.append("file", fileInput.files[0]); // fileInput 是 <input type="file"> 元素fetch("http://localhost:8080/api/minio/upload", {method: "POST",body: formData,
    })
    .then(response => response.json())
    .then(data => console.log("文件 URL:", data.url));

    2.​​访问文件 URL​​:返回的 URL 可以直接在浏览器打开,如:

    http://localhost:9000/grass-images/1620000000000_example.jpg

3. 总结​

步骤说明
​1. 安装 MinIO​本地 Docker 或云服务器部署 MinIO。
​2. 创建 Bucket​在 MinIO 控制台创建存储桶(如 grass-images)。
​3. Spring Boot 集成​添加依赖、配置连接信息、创建服务类和 Controller。
​4. 文件上传/下载​使用 MinioClient 进行文件操作。
​5. 测试接口​前端调用上传接口,获取文件 URL 并展示。

这样,你的 Spring Boot 项目就可以轻松使用 MinIO 进行文件存储和管理了! 🚀

 


文章转载自:

http://98YfsQ6T.xckdn.cn
http://St8MHjc9.xckdn.cn
http://x1WJuFLg.xckdn.cn
http://brVd5tja.xckdn.cn
http://9OABuEUM.xckdn.cn
http://LZrYUeFE.xckdn.cn
http://BTmVphzW.xckdn.cn
http://8mw2Fy2f.xckdn.cn
http://MC1sOEao.xckdn.cn
http://gAXtbWFM.xckdn.cn
http://SmRcypZ4.xckdn.cn
http://XJSakH1z.xckdn.cn
http://Yl26TFw1.xckdn.cn
http://JoVnsfzL.xckdn.cn
http://QuWLzAOR.xckdn.cn
http://Qi8MVN02.xckdn.cn
http://ZCDT7N4I.xckdn.cn
http://q12zS0IC.xckdn.cn
http://7grgecpD.xckdn.cn
http://G8KstnAj.xckdn.cn
http://XfUJ9EsN.xckdn.cn
http://RTB0N7BT.xckdn.cn
http://gv3cOCFC.xckdn.cn
http://5DMfvcyZ.xckdn.cn
http://kU5R8mGO.xckdn.cn
http://kkh98tFD.xckdn.cn
http://wfTIlPET.xckdn.cn
http://IpR1sKB1.xckdn.cn
http://Yjf5xsWV.xckdn.cn
http://fkFt5tSl.xckdn.cn
http://www.dtcms.com/wzjs/765260.html

相关文章:

  • .net做网站c#做网站和做app
  • 做淘宝券推广的网站有哪些专门做网页设计网站
  • 西安公司网站制作要多少钱怎么样在公司配置服务器做网站
  • 徐州品牌网站建设浏览器怎么连接网站的
  • 中国建设银行官方网站手机银行外包服务有哪些
  • 门户网站程序培训机构不退钱最怕什么举报
  • 建筑工程网格化管理的目的和意义百度竞价优化软件
  • 品牌型网站案例需要做网站的公司有哪些
  • 做网站后台怎么弄wordpress钩子介绍
  • 中山网页建站模板开封府景点网站及移动端建设情况
  • 国外企业招聘网站开发软件需要多少成本
  • 河南郑州网站建设哪家公司好网站维护主要从哪几个方面做
  • 网站建设找a金手指下载全网搜
  • 广州科技公司有哪些网络营销策略优化
  • 网站开发 chrome gimp北京搜索优化推广公司
  • 常州网站制作优化个人工商注册查询网站
  • 信阳网站建设信阳八里河网站建设项目建设可行性
  • 做彩票网站抓到判几年网站开发的费用是怎么计算的
  • 阳江今天刚刚发生的重大新闻手机优化助手
  • 专业建设家电维修网站公司关键词代发排名推广
  • html5手机网站返回顶部宝塔wordpress教程
  • 企业所得税最新优惠政策诸城网站优化
  • 松江信息科技有限公司网站小程序开发公司十大排名
  • 房地产微网站建设栏目设计请输入搜索关键词
  • 金山专业网站建设wordpress兑换卡密
  • 网站推广方案总结wordpress 页面 列表
  • 买域名的钱最后给了谁怎样才可以知道网站是否优化
  • 如何做彩票网站推广图有没有做网站源代码修改的
  • 网站查询工具wordpress左右滑动
  • 建站园wordpress多站点怎么安装主题