新闻详情

新闻详情

首页 / 资讯中心 / 详情

SpringBoot 集成 RustFS

发布时间:2026/9/30 17:38:48来源:尧图网络
SpringBoot 集成 RustFS
SpringBoot 集成 RustFS1 配置1.1 Docker容器1.2 Spring配置2 依赖3 代码3.1 FileController3.2 RustFsConfig3.3 RustFsProperties3.4 RustFsStorageService1 配置1.1 Docker容器services:rustfs:image:rustfs/rustfs:latestcontainer_name:rustfsrestart:unless-stoppedsecurity_opt:-no-new-privileges:truenetworks:-hyacinthports:-9500:9000# S3 API避开 MinIO 的 9000-9501:9001# RustFS 控制台environment:# 本机单磁盘开发模式避免把同一物理磁盘伪装成四块独立磁盘。RUSTFS_VOLUMES:/dataRUSTFS_ADDRESS:0.0.0.0:9000RUSTFS_CONSOLE_ADDRESS:0.0.0.0:9001RUSTFS_CONSOLE_ENABLE:trueRUSTFS_CONSOLE_CORS_ALLOWED_ORIGINS:*RUSTFS_ACCESS_KEY:rustfsadminRUSTFS_SECRET_KEY:rustfsadminRUSTFS_OBS_LOGGER_LEVEL:infoRUSTFS_OBS_LOG_DIRECTORY:/app/logsvolumes:-D:/Env/docker/rustfs/data:/data-D:/Env/docker/rustfs/logs:/app/logs1.2 Spring配置spring:application:name:spring-fileservlet:multipart:max-file-size:100MBmax-request-size:100MBrustfs:endpoint:${RUSTFS_ENDPOINT:http://localhost:9500}access-key:${RUSTFS_ACCESS_KEY:rustfsadmin}secret-key:${RUSTFS_SECRET_KEY:rustfsadmin}region:${RUSTFS_REGION:us-east-1}bucket:${RUSTFS_BUCKET:spring-file}2 依赖?xml version1.0 encodingUTF-8?projectxmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersionparentgroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-parent/artifactIdversion4.1.1/versionrelativePath//parentgroupIdcom.xu/groupIdartifactIdspring-file/artifactIdversion1.0.0/versionpropertiesjava.version25/java.version/propertiesdependencyManagementdependenciesdependencygroupIdsoftware.amazon.awssdk/groupIdartifactIdbom/artifactIdversion2.55.6/versiontypepom/typescopeimport/scope/dependency/dependencies/dependencyManagementdependenciesdependencygroupIdsoftware.amazon.awssdk/groupIdartifactIds3/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-webmvc/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-devtools/artifactIdscoperuntime/scopeoptionaltrue/optional/dependencydependencygroupIdorg.projectlombok/groupIdartifactIdlombok/artifactIdoptionaltrue/optional/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-webmvc-test/artifactIdscopetest/scope/dependency/dependenciesbuildpluginsplugingroupIdorg.graalvm.buildtools/groupIdartifactIdnative-maven-plugin/artifactId/pluginplugingroupIdorg.springframework.boot/groupIdartifactIdspring-boot-maven-plugin/artifactId/pluginplugingroupIdorg.apache.maven.plugins/groupIdartifactIdmaven-compiler-plugin/artifactIdexecutionsexecutioniddefault-compile/idphasecompile/phasegoalsgoalcompile/goal/goalsconfigurationannotationProcessorPathspathgroupIdorg.projectlombok/groupIdartifactIdlombok/artifactId/path/annotationProcessorPaths/configuration/executionexecutioniddefault-testCompile/idphasetest-compile/phasegoalsgoaltestCompile/goal/goalsconfigurationannotationProcessorPathspathgroupIdorg.projectlombok/groupIdartifactIdlombok/artifactId/path/annotationProcessorPaths/configuration/execution/executions/plugin/plugins/build/project3 代码3.1 FileControllerpackagecom.xu.spring.file.rustfs;importjava.io.IOException;importjava.util.Map;importorg.springframework.http.MediaType;importorg.springframework.web.bind.annotation.DeleteMapping;importorg.springframework.web.bind.annotation.PathVariable;importorg.springframework.web.bind.annotation.PostMapping;importorg.springframework.web.bind.annotation.RequestMapping;importorg.springframework.web.bind.annotation.RequestParam;importorg.springframework.web.bind.annotation.RestController;importorg.springframework.web.multipart.MultipartFile;RestControllerRequestMapping(/api/files)publicclassFileController{privatefinalRustFsStorageServicestorageService;publicFileController(RustFsStorageServicestorageService){this.storageServicestorageService;}PostMapping(consumes{MediaType.MULTIPART_FORM_DATA_VALUE,MediaType.MULTIPART_MIXED_VALUE})publicMapString,Stringupload(RequestParam(file)MultipartFilefile)throwsIOException{StringobjectKeystorageService.upload(file);returnMap.of(message,上传成功,key,objectKey);}DeleteMapping(/{key})publicMapString,Stringdelete(PathVariableStringkey){storageService.delete(key);returnMap.of(message,删除成功);}}3.2 RustFsConfigpackagecom.xu.spring.file.rustfs;importjava.net.URI;importorg.springframework.boot.context.properties.EnableConfigurationProperties;importorg.springframework.context.annotation.Bean;importorg.springframework.context.annotation.Configuration;importsoftware.amazon.awssdk.auth.credentials.AwsBasicCredentials;importsoftware.amazon.awssdk.auth.credentials.StaticCredentialsProvider;importsoftware.amazon.awssdk.regions.Region;importsoftware.amazon.awssdk.services.s3.S3Client;ConfigurationEnableConfigurationProperties(RustFsProperties.class)publicclassRustFsConfig{BeanpublicS3ClientrustFsS3Client(RustFsPropertiesproperties){AwsBasicCredentialscredentialsAwsBasicCredentials.create(properties.accessKey(),properties.secretKey());returnS3Client.builder().endpointOverride(URI.create(properties.endpoint())).region(Region.of(properties.region())).credentialsProvider(StaticCredentialsProvider.create(credentials)).forcePathStyle(true).build();}}3.3 RustFsPropertiespackagecom.xu.spring.file.rustfs;importorg.springframework.boot.context.properties.ConfigurationProperties;ConfigurationProperties(prefixrustfs)publicrecordRustFsProperties(Stringendpoint,StringaccessKey,StringsecretKey,Stringregion,Stringbucket){}3.4 RustFsStorageServicepackagecom.xu.spring.file.rustfs;importjava.io.IOException;importjava.io.InputStream;importjava.util.UUID;importorg.springframework.stereotype.Service;importorg.springframework.util.StringUtils;importorg.springframework.web.multipart.MultipartFile;importsoftware.amazon.awssdk.core.sync.RequestBody;importsoftware.amazon.awssdk.services.s3.S3Client;importsoftware.amazon.awssdk.services.s3.model.DeleteObjectRequest;importsoftware.amazon.awssdk.services.s3.model.PutObjectRequest;ServicepublicclassRustFsStorageService{privatefinalS3Clients3Client;privatefinalRustFsPropertiesproperties;publicRustFsStorageService(S3Clients3Client,RustFsPropertiesproperties){this.s3Clients3Client;this.propertiesproperties;}publicStringupload(MultipartFilefile)throwsIOException{if(file.isEmpty()){thrownewIllegalArgumentException(上传文件不能为空);}Stringsuffix;StringoriginalFilenamefile.getOriginalFilename();if(StringUtils.hasText(originalFilename)){intindexoriginalFilename.lastIndexOf(.);if(index0){suffixoriginalFilename.substring(index);}}StringobjectKeyUUID.randomUUID()suffix;PutObjectRequestrequestPutObjectRequest.builder().bucket(properties.bucket()).key(objectKey).contentType(StringUtils.hasText(file.getContentType())?file.getContentType():application/octet-stream).build();try(InputStreaminputStreamfile.getInputStream()){s3Client.putObject(request,RequestBody.fromInputStream(inputStream,file.getSize()));}returnobjectKey;}publicvoiddelete(StringobjectKey){DeleteObjectRequestrequestDeleteObjectRequest.builder().bucket(properties.bucket()).key(objectKey).build();s3Client.deleteObject(request);}}
网站建设高端定制企业官网
RELATED

相关资讯

更多精彩内容,欢迎继续阅读

较早相关资讯

最新相关资讯

实验报告基于江协科技固件库和HAK库的STM32实验:LED流水灯与HAL库设置按键暂停 2026/9/30 18:36:30

实验报告基于江协科技固件库和HAK库的STM32实验:LED流水灯与HAL库设置按键暂停

基于江协科技固件库和HAK库的STM32实验:LED流水灯与HAL库设置按键暂停实验任务一可参考本人之前的博客1.实验任务:固件库LED流水灯 项目创建与固件库文件添加 创建工程文件夹 复制标准外设库文件 从江协科技提供的固件库(STM32F10x_StdPeriph…

阅读更多 →
本地知识库搭建指南:ollama+langchain+chroma,旧电脑也能跑 2026/9/30 18:36:15

本地知识库搭建指南:ollama+langchain+chroma,旧电脑也能跑

1. 为什么我劝你别急着开云会员去年年底我把自己那台老笔记本翻出来,装了个本地知识库,跑了大半年,最大的感受就一句话:云会员的钱,大部分是白花的。我身边不少朋友,手机是华为的,平板是小米的&…

阅读更多 →
Kiro 反代 Claude 模型给 Claude Code 使用:kiro-account-manager 一键搞定 2026/9/30 18:36:15

Kiro 反代 Claude 模型给 Claude Code 使用:kiro-account-manager 一键搞定

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

阅读更多 →
神经网络MOSFET模型泛化能力:物理约束与SPICE部署实战 2026/9/30 18:36:07

神经网络MOSFET模型泛化能力:物理约束与SPICE部署实战

简介:这份PDF文献面向电路设计、器件建模方向的研究生与工程师,聚焦神经网络在MOSFET建模中的泛化能力问题。资源为单篇学术论文,压缩包内仅含1个PDF文件,约1.02MB,轻量便于随时查阅。论文提出一种分段建模思路&#x…

阅读更多 →
Codex CLI接入Jev模型与CC Switch多Provider配置实战指南 2026/9/30 18:36:00

Codex CLI接入Jev模型与CC Switch多Provider配置实战指南

Codex CLI我用得不算早,但用得挺狠,几乎每天都挂在终端里干活。最初那段时间确实爽,毕竟官方出品的编码智能体,在终端里画架构图、改bug、跑测试,比在IDE里来回切窗口舒服多了。可问题也随着深入使用一点点冒出来&…

阅读更多 →
用AI Agent搭建投资研究自动化系统:Python工程化与本地部署实战 2026/9/30 18:35:37

用AI Agent搭建投资研究自动化系统:Python工程化与本地部署实战

1. 为什么我要把投资研究交给 AI Agent 先说结论:我不是让 AI 替我拍板买卖,而是让它替我干那些"重复、耗时、但必须做"的脏活累活。这个区别很关键,想清楚这一点,后面所有的架构设计才有意义。 我做投资研究有些年头了…

阅读更多 →

今日资讯

本周资讯

本月资讯

看完文章仍有疑问?

联系尧图顾问,获取一对一建站咨询

立即免费咨询 📞 400-888-8888
📞 ✉