Appearance
云存储中间件集成组件
兼容S3协议的通用文件存储组件 ,支持兼容S3协议的云存储,如:
- MINIO
- 阿里云
- 华为云
- 腾讯云
- 京东云
...
spring boot starter依赖
- 方便在 web 环境下使用
oss
,已上传至 maven 仓库
xml
<dependency>
<groupId>com.chinapost.mids</groupId>
<artifactId>cpms-oss-spring-boot-starter</artifactId>
<version>1.0.0-RELEASE</version>
</dependency>
使用方法
配置文件
yaml
oss:
enable: true
region:
endpoint: https://play.min.io:9000
custom-domain: https://oss.xxx.com/bfp
# 采用nginx反向代理或者AWS S3配置成true,支持第三方云存储配置成false
# 如使用云OSS需要配置为false
path-style-access: false
access-key: xxx
secret-key: xxx
bucketName: pig4cloud
代码使用
java
@Autowired
private OssTemplate template;
/**
* 上传文件
* 文件名采用uuid,避免原始文件名中带"-"符号导致下载的时候解析出现异常
*
* @param file 资源
* @return R(bucketName, filename)
*/
@PostMapping("/upload")
public R upload(@RequestParam("file") MultipartFile file, HttpServletRequest request) {
template.putObject(CommonConstants.BUCKET_NAME, fileName, file.getInputStream());
return R.ok(resultMap);
}