简洁大气的企业网站,网站开发工程师好不好,做头像的网站自己的名字,查流量网站spring boot文件上传之x-file-storage
今天看到一个文件上传的开源组件x-file-storage#xff0c;官方地址如下#xff1a;
https://x-file-storage.xuyanwu.cn/#/
该组件官网是这样介绍的#xff0c;如下#xff1a;
一行代码将文件存储到本地、FTP、SFTP、WebDAV、阿…spring boot文件上传之x-file-storage
今天看到一个文件上传的开源组件x-file-storage官方地址如下
https://x-file-storage.xuyanwu.cn/#/
该组件官网是这样介绍的如下
一行代码将文件存储到本地、FTP、SFTP、WebDAV、阿里云 OSS、华为云 OBS、七牛云 Kodo、腾讯云 COS、百度云 BOS、又拍云 USS、MinIO、 Amazon S3、GoogleCloud Storage、FastDFS、 Azure Blob Storage、Cloudflare R2、金山云 KS3、美团云 MSS、京东云 OSS、天翼云 OOS、移动 云EOS、沃云 OSS、 网易数帆 NOS、Ucloud US3、青云 QingStor、平安云 OBS、首云 OSS、IBM COS、其它兼容 S3 协议的存储平台。查看 所有支持的存储平台
具体学习的话可以详细参考该组件网站给的示例
这里以springboot3为例文件上传到本地做了一个简单测试代码如下
第一步引入pom依赖 dependencygroupIdorg.dromara.x-file-storage/groupIdartifactIdx-file-storage-spring/artifactIdversion2.2.1/version/dependency第二步配置yaml
dromara:x-file-storage: default-platform: local-plus-1 thumbnail-suffix: .min.jpg local-plus:- platform: local-plus-1 enable-storage: true enable-access: true domain: http://127.0.0.1:8080/file/ base-path: local-plus/path-patterns: /file/** storage-path: D:/Temp/ 第三步编写controller
RestController
public class FileController {Autowiredprivate FileStorageService fileStorageService;/*** 上传文件*/PostMapping(/upload)public FileInfo upload(RequestParam(file)MultipartFile file) {String originalFilename file.getOriginalFilename();FileInfo upload fileStorageService.of(file).setSaveFilename(originalFilename).upload();return upload;}
}第四步启动类上添加开启启用该组件注解
SpringBootApplication
EnableFileStorage
public class XFileStorageApplication {public static void main(String[] args) {SpringApplication.run(XFileStorageApplication.class, args);}}
最后启动项目进行测试使用postman进行发送请求
然后到 yaml 配置文件指定的位置进行查看