# 介绍

目前各大云厂商都提供了云对象存储服务(COS),为了简化接入成本以及实现一套代码兼容各种云厂商,于是就有了本项目。本项目作为各云存储服务的中间适配层,只需要修改配置即可轻松切换云存储服务提供商。

# 使用说明

# 添加依赖

<dependency>
	<groupId>com.mendmix</groupId>
	<artifactId>mendmix-cos-adapter</artifactId>
	<version>[最新版本]</version>
</dependency>

<!--接入七牛需加入-->
<dependency>
	<groupId>com.qiniu</groupId>
	<artifactId>qiniu-java-sdk</artifactId>
	<version>7.12.0</version>
</dependency>

<!--接入阿里云需加入-->
<dependency>
	<groupId>com.aliyun.oss</groupId>
	<artifactId>aliyun-sdk-oss</artifactId>
	<version>3.11.3</version>
</dependency>

<!--接入腾讯云需加入-->
<dependency>
	<groupId>com.qcloud</groupId>
	<artifactId>cos_api</artifactId>
	<version>5.6.39</version>
</dependency>

<!--接入华为云需加入-->
<dependency>
	<groupId>com.huaweicloud</groupId>
	<artifactId>esdk-obs-java-bundle</artifactId>
	<version>[3.21.8,)</version>
</dependency>

# 配置说明

配置项 必填 说明
mendmix.cos.provider 可选:aliyun,qcloud,qiniu,huaweicloud,aws,minio,localStorage
mendmix.cos.accessKey 云服务商提供
mendmix.cos.secretKey 云服务商提供
mendmix.cos.appId 目前仅腾讯云需要
mendmix.cos.endpoint 目前仅腾讯云需要
mendmix.cos.regionName 七牛云(如:huanan),腾讯云(如:ap-guangzhou),阿里云(如:cn-guangzhou)
mendmix.cos.defaultBucket 如果上传不指定bucket,就使用默认的
mendmix.cos.maxFileSize 支持最大文件大小,默认不限制
mendmix.cos.maxConnections 客户端最大连接数,默认:100
mendmix.cos.fileWithDate 是否生成带日期的文件key

# 用法

引入相关依赖,增加如下配置即可自动注册

mendmix.cos.provider=qiniu
mendmix.cos.accessKey=
mendmix.cos.xxx= (参考上述配置)

不依赖任何文件服务本地上传配置

mendmix.cos.provider=localStorage
mendmix.cos.endpoint=/Users/jiangwei/datas/tmp
mendmix.cos.defaultBucket=files
mendmix.cos.defaultUrlPrefix=http://127.0.0.1:8080/api/file

用法:

@Autowired
private CosProviderServiceFacade cosProviderService;
//上传
cosProviderService.upload(object);
Last Updated: 6/14/2022, 9:51:10 PM