├── docs
├── aws
│ └── README.md
├── pingan
│ └── README.md
├── local
│ └── README.md
├── ftp
│ └── README.md
├── sftp
│ └── README.md
├── qiniu
│ └── README.md
├── huawei
│ └── README.md
├── qingyun
│ └── README.md
├── ali
│ └── README.md
├── up
│ └── README.md
├── baidu
│ └── README.md
├── jinshan
│ └── README.md
├── jd
│ └── README.md
├── jdbc
│ └── README.md
├── tencent
│ └── README.md
├── ucloud
│ └── README.md
├── wangyi
│ └── README.md
└── minio
│ └── README.md
├── .gitignore
└── src
├── main
├── java
│ └── io
│ │ └── github
│ │ └── artislong
│ │ ├── core
│ │ ├── baidu
│ │ │ ├── constant
│ │ │ │ └── BaiduOssConstant.java
│ │ │ ├── model
│ │ │ │ ├── BaiduOssConfig.java
│ │ │ │ └── BaiduOssClientConfig.java
│ │ │ ├── BaiduOssProperties.java
│ │ │ └── BaiduOssConfiguration.java
│ │ ├── qingyun
│ │ │ ├── constant
│ │ │ │ └── QingYunOssConstant.java
│ │ │ ├── model
│ │ │ │ ├── QingYunOssConfig.java
│ │ │ │ └── QingYunOssClientConfig.java
│ │ │ └── QingYunOssProperties.java
│ │ ├── up
│ │ │ ├── constant
│ │ │ │ ├── UpConstant.java
│ │ │ │ └── ApiDomain.java
│ │ │ ├── model
│ │ │ │ ├── UpOssClientConfig.java
│ │ │ │ └── UpOssConfig.java
│ │ │ ├── UpOssProperties.java
│ │ │ └── UpOssConfiguration.java
│ │ ├── jdbc
│ │ │ ├── constant
│ │ │ │ └── JdbcOssConstant.java
│ │ │ ├── model
│ │ │ │ ├── JdbcOssConfig.java
│ │ │ │ └── JdbcOssInfo.java
│ │ │ └── JdbcOssProperties.java
│ │ ├── jinshan
│ │ │ ├── model
│ │ │ │ ├── Ks3ClientConfig.java
│ │ │ │ ├── JinShanOssConfig.java
│ │ │ │ └── JinShanOssClientConfig.java
│ │ │ └── JinShanOssProperties.java
│ │ ├── local
│ │ │ ├── model
│ │ │ │ └── LocalOssConfig.java
│ │ │ ├── LocalOssProperties.java
│ │ │ └── LocalOssConfiguration.java
│ │ ├── sftp
│ │ │ ├── model
│ │ │ │ ├── SftpOssClientConfig.java
│ │ │ │ └── SftpOssConfig.java
│ │ │ ├── SftpOssProperties.java
│ │ │ ├── SftpOssConfiguration.java
│ │ │ └── DefaultSftpProgressMonitor.java
│ │ ├── aws
│ │ │ ├── model
│ │ │ │ ├── AwsOssClientConfig.java
│ │ │ │ └── AwsOssConfig.java
│ │ │ ├── AwsOssProperties.java
│ │ │ └── constant
│ │ │ │ └── AwsRegion.java
│ │ ├── qiniu
│ │ │ ├── model
│ │ │ │ ├── QiNiuOssConfig.java
│ │ │ │ └── QiNiuOssClientConfig.java
│ │ │ ├── QiNiuOssProperties.java
│ │ │ └── constant
│ │ │ │ └── QiNiuRegion.java
│ │ ├── wangyi
│ │ │ ├── model
│ │ │ │ ├── WangYiOssConfig.java
│ │ │ │ └── WangYiOssClientConfig.java
│ │ │ ├── WangYiOssProperties.java
│ │ │ └── WangYiOssConfiguration.java
│ │ ├── tencent
│ │ │ ├── model
│ │ │ │ ├── TencentOssConfig.java
│ │ │ │ └── TencentOssClientConfig.java
│ │ │ ├── TencentOssProperties.java
│ │ │ ├── constant
│ │ │ │ └── TencentOssConstant.java
│ │ │ └── TencentOssConfiguration.java
│ │ ├── ucloud
│ │ │ ├── model
│ │ │ │ ├── UCloudOssConfig.java
│ │ │ │ └── UCloudOssClientConfig.java
│ │ │ ├── UCloudOssProperties.java
│ │ │ └── UCloudOssConfiguration.java
│ │ ├── minio
│ │ │ ├── model
│ │ │ │ ├── MinioOssConfig.java
│ │ │ │ └── MinioOssClientConfig.java
│ │ │ ├── MinioOssProperties.java
│ │ │ └── MinioOssConfiguration.java
│ │ ├── jd
│ │ │ ├── model
│ │ │ │ └── JdOssConfig.java
│ │ │ └── JdOssProperties.java
│ │ ├── ftp
│ │ │ ├── model
│ │ │ │ ├── FtpOssClientConfig.java
│ │ │ │ └── FtpOssConfig.java
│ │ │ ├── FtpOssProperties.java
│ │ │ └── FtpOssConfiguration.java
│ │ ├── pingan
│ │ │ ├── model
│ │ │ │ └── PingAnOssConfig.java
│ │ │ └── PingAnOssProperties.java
│ │ ├── huawei
│ │ │ ├── model
│ │ │ │ └── HuaweiOssConfig.java
│ │ │ ├── HuaWeiOssProperties.java
│ │ │ └── HuaWeiOssConfiguration.java
│ │ └── ali
│ │ │ ├── model
│ │ │ └── AliOssConfig.java
│ │ │ └── AliOssProperties.java
│ │ ├── OssProperties.java
│ │ ├── model
│ │ ├── FileOssInfo.java
│ │ ├── OssInfo.java
│ │ ├── DirectoryOssInfo.java
│ │ ├── download
│ │ │ ├── DownloadPartResult.java
│ │ │ ├── DownloadObjectStat.java
│ │ │ └── DownloadPart.java
│ │ ├── SliceConfig.java
│ │ └── upload
│ │ │ ├── UploadPart.java
│ │ │ ├── UpLoadPartResult.java
│ │ │ ├── UpLoadFileStat.java
│ │ │ └── UpLoadPartEntityTag.java
│ │ ├── OssAutoConfiguration.java
│ │ ├── exception
│ │ ├── OssException.java
│ │ ├── DuplicateException.java
│ │ └── NotSupportException.java
│ │ ├── constant
│ │ ├── OssConstant.java
│ │ └── OssType.java
│ │ └── utils
│ │ └── OssPathUtil.java
└── resources
│ ├── jdbc
│ ├── schema-mysql.sql
│ └── schema-oracle.sql
│ └── META-INF
│ └── spring.factories
└── test
└── java
└── io
└── github
└── artislong
├── OssApplication.java
├── OssApplicationTests.java
└── core
├── ftp
└── FtpOssClientTest.java
├── wangyi
└── WangYiOssClientTest.java
├── aws
└── AwsOssClientTest.java
├── jdbc
└── JdbcOssClientTest.java
├── ali
└── AliOssClientTest.java
├── up
└── UpOssClientTest.java
├── sftp
└── SftpOssClientTest.java
├── jd
└── JdOssClientTest.java
├── baidu
└── BaiduOssClientTest.java
├── local
└── LocalOssClientTest.java
├── minio
└── MinioOssClientTest.java
├── qiniu
└── QiNiuOssClientTest.java
├── huawei
└── HuaWeiOssClientTest.java
├── jinshan
└── JinShanOssClientTest.java
├── qingyun
└── QingYunOssClientTest.java
├── tencent
└── TencentOssClientTest.java
└── StandardOssClientTest.java
/docs/aws/README.md:
--------------------------------------------------------------------------------
1 | 暂无测试环境,待测试,文档待补充
--------------------------------------------------------------------------------
/docs/pingan/README.md:
--------------------------------------------------------------------------------
1 | 暂无测试环境,待测试,文档待补充
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | oss-spring-boot-starter.iml
2 | target
3 | src/test/resources/application.yml
4 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/baidu/constant/BaiduOssConstant.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.baidu.constant;
2 |
3 | /**
4 | * @author 陈敏
5 | * @version BaiduOssConstant.java, v 1.0 2022/4/20 16:19 chenmin Exp $
6 | * Created on 2022/4/20
7 | */
8 | public class BaiduOssConstant {
9 | public static final String DEFAULT_ENDPOINT = "bj.bcebos.com";
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/qingyun/constant/QingYunOssConstant.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.qingyun.constant;
2 |
3 | /**
4 | * @author 陈敏
5 | * @version QingYunOssConstant.java, v 1.0 2022/5/4 21:07 chenmin Exp $
6 | * Created on 2022/5/4
7 | */
8 | public class QingYunOssConstant {
9 | public static final String DEFAULT_ENDPOINT = "https://qingstor.com";
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/up/constant/UpConstant.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.up.constant;
2 |
3 | /**
4 | * @author 陈敏
5 | * @version UpConstant.java, v 1.1 2021/12/4 19:13 chenmin Exp $
6 | * Created on 2021/12/4
7 | */
8 | public class UpConstant {
9 | public static final String FILE_TYPE = "N";
10 | public static final String DIRECTORY_TYPE = "Y";
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/OssProperties.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong;
2 |
3 | import lombok.Data;
4 | import org.springframework.boot.context.properties.ConfigurationProperties;
5 |
6 | /**
7 | * @author 陈敏
8 | * @version OssProperties.java, v 1.1 2021/11/5 11:05 chenmin Exp $
9 | * Created on 2021/11/5
10 | */
11 | @Data
12 | @ConfigurationProperties(prefix = "oss")
13 | public class OssProperties {
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/jdbc/constant/JdbcOssConstant.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.jdbc.constant;
2 |
3 | /**
4 | * @author 陈敏
5 | * @version JdbcOssConstant.java, v 1.0 2022/3/12 15:50 chenmin Exp $
6 | * Created on 2022/3/12
7 | */
8 | public class JdbcOssConstant {
9 | public static class OSS_TYPE {
10 | public static final String FILE = "F";
11 | public static final String DIRECTORY = "D";
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/model/FileOssInfo.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.model;
2 |
3 | import lombok.Data;
4 | import lombok.EqualsAndHashCode;
5 | import lombok.ToString;
6 | import lombok.experimental.Accessors;
7 |
8 | /**
9 | * 文件信息对象
10 | * @author 陈敏
11 | * @version FileInfo.java, v 1.1 2021/11/15 10:19 chenmin Exp $
12 | * Created on 2021/11/15
13 | */
14 | @Data
15 | @Accessors(chain = true)
16 | @EqualsAndHashCode(callSuper = true)
17 | @ToString(callSuper = true)
18 | public class FileOssInfo extends OssInfo {
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/src/test/java/io/github/artislong/OssApplication.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | /**
7 | * @author 陈敏
8 | * @version OssApplication.java, v 1.1 2021/11/5 14:51 chenmin Exp $
9 | * Created on 2021/11/5
10 | */
11 | @SpringBootApplication
12 | public class OssApplication {
13 |
14 | public static void main(String[] args) {
15 | SpringApplication.run(OssApplication.class);
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/jinshan/model/Ks3ClientConfig.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.jinshan.model;
2 |
3 | /**
4 | * @author 陈敏
5 | * @version Ks3ClientConfig.java, v 1.0 2022/5/2 21:30 chenmin Exp $
6 | * Created on 2022/5/2
7 | */
8 | public class Ks3ClientConfig extends com.ksyun.ks3.service.Ks3ClientConfig {
9 |
10 | private SignerVersion version = SignerVersion.V2;
11 |
12 | @Override
13 | public SignerVersion getVersion() {
14 | return version;
15 | }
16 |
17 | @Override
18 | public void setVersion(SignerVersion version) {
19 | this.version = version;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/up/model/UpOssClientConfig.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.up.model;
2 |
3 | import io.github.artislong.core.up.constant.ApiDomain;
4 | import lombok.Data;
5 | import lombok.experimental.Accessors;
6 |
7 | /**
8 | * @author 陈敏
9 | * @version UpOssClientConfig.java, v 1.0 2022/4/21 10:15 chenmin Exp $
10 | * Created on 2022/4/21
11 | */
12 | @Data
13 | @Accessors(chain = true)
14 | public class UpOssClientConfig {
15 |
16 | /**
17 | * 默认的超时时间:30秒
18 | */
19 | private int timeout = 30;
20 | /**
21 | * 默认为自动识别接入点
22 | */
23 | private ApiDomain apiDomain = ApiDomain.ED_AUTO;
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/model/OssInfo.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.model;
2 |
3 | import lombok.Data;
4 |
5 | /**
6 | * @author 陈敏
7 | * @version Info.java, v 1.1 2021/11/15 10:16 chenmin Exp $
8 | * Created on 2021/11/15
9 | */
10 | @Data
11 | public class OssInfo {
12 |
13 | /**
14 | * 名称
15 | */
16 | private String name;
17 | /**
18 | * 存储路径
19 | */
20 | private String path;
21 | /**
22 | * 对象大小
23 | */
24 | private String length;
25 | /**
26 | * 创建时间
27 | */
28 | private String createTime;
29 | /**
30 | * 最新修改时间
31 | */
32 | private String lastUpdateTime;
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/OssAutoConfiguration.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong;
2 |
3 | import cn.hutool.extra.spring.EnableSpringUtil;
4 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
5 | import org.springframework.context.annotation.ComponentScan;
6 | import org.springframework.context.annotation.Configuration;
7 |
8 | /**
9 | * @author 陈敏
10 | * @version OssAutoConfiguration.java, v 1.1 2021/11/5 11:05 chenmin Exp $
11 | * Created on 2021/11/5
12 | */
13 | @EnableSpringUtil
14 | @Configuration
15 | @ComponentScan(basePackages = "io.github.artislong")
16 | @EnableConfigurationProperties(OssProperties.class)
17 | public class OssAutoConfiguration {
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/local/model/LocalOssConfig.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.local.model;
2 |
3 | import io.github.artislong.model.SliceConfig;
4 | import io.github.artislong.utils.OssPathUtil;
5 | import lombok.Data;
6 |
7 | /**
8 | * @author 陈敏
9 | * @version LocalOssConfig.java, v 1.1 2022/2/20 8:55 chenmin Exp $
10 | * Created on 2022/2/20
11 | */
12 | @Data
13 | public class LocalOssConfig {
14 |
15 | /**
16 | * 数据存储路径
17 | */
18 | private String basePath;
19 |
20 | /**
21 | * 断点续传参数
22 | */
23 | private SliceConfig sliceConfig = new SliceConfig();
24 |
25 | public void init() {
26 | this.sliceConfig.init();
27 | basePath = OssPathUtil.valid(basePath);
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/sftp/model/SftpOssClientConfig.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.sftp.model;
2 |
3 | import lombok.Data;
4 | import lombok.experimental.Accessors;
5 |
6 | /**
7 | * @author 陈敏
8 | * @version SftpOssClientConfig.java, v 1.0 2022/5/9 0:27 chenmin Exp $
9 | * Created on 2022/5/9
10 | */
11 | @Data
12 | @Accessors(chain = true)
13 | public class SftpOssClientConfig {
14 | /**
15 | * 连接超时时长,单位毫秒
16 | */
17 | private long connectionTimeout;
18 | /**
19 | * Socket连接超时时长,单位毫秒
20 | */
21 | private long soTimeout;
22 | /**
23 | * 设置服务器语言
24 | */
25 | private String serverLanguageCode;
26 | /**
27 | * 设置服务器系统关键词
28 | */
29 | private String systemKey;
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/aws/model/AwsOssClientConfig.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.aws.model;
2 |
3 | import lombok.Data;
4 |
5 | /**
6 | * @author 陈敏
7 | * @version AwsOssClientConfig.java, v 1.0 2022/4/2 16:05 chenmin Exp $
8 | * Created on 2022/4/2
9 | */
10 | @Data
11 | public class AwsOssClientConfig {
12 |
13 | private Boolean accelerateModeEnabled = false;
14 | private Boolean checksumValidationEnabled = false;
15 | private Boolean multiRegionEnabled = false;
16 | private Boolean chunkedEncodingEnabled = false;
17 | private Boolean pathStyleAccessEnabled = false;
18 | private Boolean useArnRegionEnabled = false;
19 | private Boolean fipsEnabled = false;
20 | private Boolean dualstackEnabled = false;
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/exception/OssException.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.exception;
2 |
3 | /**
4 | * @author 陈敏
5 | * @version OssException.java, v 1.1 2021/12/3 21:02 chenmin Exp $
6 | * Created on 2021/12/3
7 | */
8 | public class OssException extends RuntimeException {
9 | public OssException() {
10 | }
11 |
12 | public OssException(String message) {
13 | super(message);
14 | }
15 |
16 | public OssException(String message, Throwable cause) {
17 | super(message, cause);
18 | }
19 |
20 | public OssException(Throwable cause) {
21 | super(cause);
22 | }
23 |
24 | public OssException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
25 | super(message, cause, enableSuppression, writableStackTrace);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/up/model/UpOssConfig.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.up.model;
2 |
3 | import io.github.artislong.model.SliceConfig;
4 | import io.github.artislong.utils.OssPathUtil;
5 | import lombok.Data;
6 |
7 | /**
8 | * @author 陈敏
9 | * @version UpOssConfig.java, v 1.1 2022/2/20 9:13 chenmin Exp $
10 | * Created on 2022/2/20
11 | */
12 | @Data
13 | public class UpOssConfig {
14 |
15 | private String basePath;
16 | private String bucketName;
17 | private String userName;
18 | private String password;
19 |
20 | private UpOssClientConfig clientConfig;
21 |
22 | /**
23 | * 断点续传参数
24 | */
25 | private SliceConfig sliceConfig = new SliceConfig();
26 |
27 | public void init() {
28 | this.sliceConfig.init();
29 | basePath = OssPathUtil.valid(basePath);
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/model/DirectoryOssInfo.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.model;
2 |
3 | import lombok.Data;
4 | import lombok.EqualsAndHashCode;
5 | import lombok.ToString;
6 | import lombok.experimental.Accessors;
7 |
8 | import java.util.ArrayList;
9 | import java.util.List;
10 |
11 | /**
12 | * 文件夹信息对象
13 | * @author 陈敏
14 | * @version DirectoryInfo.java, v 1.1 2021/11/15 10:21 chenmin Exp $
15 | * Created on 2021/11/15
16 | */
17 | @Data
18 | @Accessors(chain = true)
19 | @EqualsAndHashCode(callSuper = true)
20 | @ToString(callSuper = true)
21 | public class DirectoryOssInfo extends OssInfo {
22 |
23 | /**
24 | * 文件夹列表
25 | */
26 | private List fileInfos = new ArrayList<>();
27 |
28 | /**
29 | * 文件列表
30 | */
31 | private List directoryInfos = new ArrayList<>();
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/qiniu/model/QiNiuOssConfig.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.qiniu.model;
2 |
3 | import io.github.artislong.model.SliceConfig;
4 | import io.github.artislong.utils.OssPathUtil;
5 | import lombok.Data;
6 |
7 | /**
8 | * @author 陈敏
9 | * @version QiNiuOssConfig.java, v 1.1 2022/2/20 9:02 chenmin Exp $
10 | * Created on 2022/2/20
11 | */
12 | @Data
13 | public class QiNiuOssConfig {
14 |
15 | private String basePath;
16 | private String accessKey;
17 | private String secretKey;
18 | private String bucketName;
19 | private QiNiuOssClientConfig clientConfig;
20 |
21 | /**
22 | * 断点续传参数
23 | */
24 | private SliceConfig sliceConfig = new SliceConfig();
25 |
26 | public void init() {
27 | this.sliceConfig.init();
28 | basePath = OssPathUtil.valid(basePath);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/wangyi/model/WangYiOssConfig.java:
--------------------------------------------------------------------------------
1 | /**
* $Id: WangYiOssConfig.java,v 1.0 2022/3/4 9:54 PM chenmin Exp $
*/
package io.github.artislong.core.wangyi.model;
import io.github.artislong.model.SliceConfig;
import io.github.artislong.utils.OssPathUtil;
import lombok.Data;
/**
* @author 陈敏
* @version $Id: WangYiOssConfig.java,v 1.1 2022/3/4 9:54 PM chenmin Exp $
* Created on 2022/3/4 9:54 PM
* My blog: https://www.chenmin.info
*/
@Data
public class WangYiOssConfig {
private String accessKey;
private String secretKey;
private String endpoint;
private String bucketName;
private String basePath;
private WangYiOssClientConfig clientConfig;
/**
* 断点续传参数
*/
private SliceConfig sliceConfig = new SliceConfig();
public void init() {
this.sliceConfig.init();
basePath = OssPathUtil.valid(basePath);
}
}
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/jdbc/model/JdbcOssConfig.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.jdbc.model;
2 |
3 | import io.github.artislong.utils.OssPathUtil;
4 | import lombok.Data;
5 |
6 | import javax.sql.DataSource;
7 |
8 | /**
9 | * @author 陈敏
10 | * @version JdbcOssConfig.java, v 1.0 2022/3/11 22:04 chenmin Exp $
11 | * Created on 2022/3/11
12 | */
13 | @Data
14 | public class JdbcOssConfig {
15 |
16 | private String basePath;
17 |
18 | /**
19 | * 系统数据源Bean名称(适用于系统多数据源配置)
20 | */
21 | private String dataSourceName;
22 |
23 | /**
24 | * 对象存储数据源
25 | */
26 | private String url;
27 | private Class extends DataSource> type;
28 | private String driver;
29 | private String username;
30 | private String password;
31 |
32 | public void init() {
33 | basePath = OssPathUtil.valid(basePath);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/tencent/model/TencentOssConfig.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.tencent.model;
2 |
3 | import io.github.artislong.model.SliceConfig;
4 | import io.github.artislong.utils.OssPathUtil;
5 | import lombok.Data;
6 |
7 | /**
8 | * @author 陈敏
9 | * @version TencentOssConfig.java, v 1.1 2022/2/20 9:10 chenmin Exp $
10 | * Created on 2022/2/20
11 | */
12 | @Data
13 | public class TencentOssConfig {
14 |
15 | private String basePath;
16 | private String bucketName;
17 | private String secretId;
18 | private String secretKey;
19 |
20 | private TencentOssClientConfig clientConfig;
21 |
22 | /**
23 | * 断点续传参数
24 | */
25 | private SliceConfig sliceConfig = new SliceConfig();
26 |
27 | public void init() {
28 | this.sliceConfig.init();
29 | basePath = OssPathUtil.valid(basePath);
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/exception/DuplicateException.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.exception;
2 |
3 | /**
4 | * @author 陈敏
5 | * @version DuplicateException.java, v 1.1 2021/11/15 15:27 chenmin Exp $
6 | * Created on 2021/11/15
7 | */
8 | public class DuplicateException extends OssException {
9 | public DuplicateException() {
10 | super();
11 | }
12 |
13 | public DuplicateException(String message) {
14 | super(message);
15 | }
16 |
17 | public DuplicateException(String message, Throwable cause) {
18 | super(message, cause);
19 | }
20 |
21 | public DuplicateException(Throwable cause) {
22 | super(cause);
23 | }
24 |
25 | protected DuplicateException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
26 | super(message, cause, enableSuppression, writableStackTrace);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/test/java/io/github/artislong/OssApplicationTests.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong;
2 |
3 | import cn.hutool.core.util.StrUtil;
4 | import org.junit.jupiter.api.Test;
5 |
6 | import java.util.List;
7 |
8 | /**
9 | * @author 陈敏
10 | * @version OssApplicationTests.java, v 1.1 2021/11/5 14:52 chenmin Exp $
11 | * Created on 2021/11/5
12 | */
13 | //@SpringBootTest
14 | public class OssApplicationTests {
15 |
16 | @Test
17 | public void context() {
18 | mkdir("/Study/test/test1/test2");
19 | }
20 |
21 | public void mkdir(String path) {
22 | List paths = StrUtil.split(path, StrUtil.SLASH, true, true);
23 | StringBuilder fullPath = new StringBuilder();
24 | for (String p : paths) {
25 | fullPath.append(StrUtil.SLASH + p);
26 | System.out.println(p);
27 | }
28 | System.out.println(fullPath);
29 |
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/exception/NotSupportException.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.exception;
2 |
3 | /**
4 | * @author 陈敏
5 | * @version NotSupportException.java, v 1.1 2021/12/3 15:04 chenmin Exp $
6 | * Created on 2021/12/3
7 | */
8 | public class NotSupportException extends OssException {
9 | public NotSupportException() {
10 | super();
11 | }
12 |
13 | public NotSupportException(String message) {
14 | super(message);
15 | }
16 |
17 | public NotSupportException(String message, Throwable cause) {
18 | super(message, cause);
19 | }
20 |
21 | public NotSupportException(Throwable cause) {
22 | super(cause);
23 | }
24 |
25 | protected NotSupportException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
26 | super(message, cause, enableSuppression, writableStackTrace);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/ucloud/model/UCloudOssConfig.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.ucloud.model;
2 |
3 | import io.github.artislong.model.SliceConfig;
4 | import io.github.artislong.utils.OssPathUtil;
5 | import lombok.Data;
6 |
7 | /**
8 | * @author 陈敏
9 | * @version UCloudOssConfig.java, v 1.1 2022/3/7 0:20 chenmin Exp $
10 | * Created on 2022/3/7
11 | */
12 | @Data
13 | public class UCloudOssConfig {
14 |
15 | private String basePath;
16 | private String bucketName;
17 | private String publicKey;
18 | private String privateKey;
19 | private String customHost;
20 |
21 | private UCloudOssClientConfig clientConfig;
22 |
23 | /**
24 | * 断点续传参数
25 | */
26 | private SliceConfig sliceConfig = new SliceConfig();
27 |
28 | public void init() {
29 | this.sliceConfig.init();
30 | basePath = OssPathUtil.valid(basePath);
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/minio/model/MinioOssConfig.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.minio.model;
2 |
3 | import io.github.artislong.model.SliceConfig;
4 | import io.github.artislong.utils.OssPathUtil;
5 | import lombok.Data;
6 |
7 | /**
8 | * @author 陈敏
9 | * @version MinioOssConfig.java, v 1.1 2022/2/20 8:58 chenmin Exp $
10 | * Created on 2022/2/20
11 | */
12 | @Data
13 | public class MinioOssConfig {
14 |
15 | private String basePath;
16 | private String endpoint;
17 | private String accessKey;
18 | private String secretKey;
19 | private String bucketName;
20 |
21 | private MinioOssClientConfig clientConfig = new MinioOssClientConfig();
22 |
23 | /**
24 | * 断点续传参数
25 | */
26 | private SliceConfig sliceConfig = new SliceConfig();
27 |
28 | public void init() {
29 | this.sliceConfig.init();
30 | basePath = OssPathUtil.valid(basePath);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/jd/model/JdOssConfig.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.jd.model;
2 |
3 | import io.github.artislong.model.SliceConfig;
4 | import io.github.artislong.utils.OssPathUtil;
5 | import lombok.Data;
6 |
7 | /**
8 | * @author 陈敏
9 | * @version JdOssConfig.java, v 1.1 2022/2/19 18:36 chenmin Exp $
10 | * Created on 2022/2/19
11 | */
12 | @Data
13 | public class JdOssConfig {
14 |
15 | private String basePath;
16 |
17 | private String bucketName;
18 | private String endpoint;
19 | private String accessKey;
20 | private String secretKey;
21 |
22 | private String region;
23 |
24 | private JdOssClientConfig clientConfig;
25 |
26 | /**
27 | * 断点续传参数
28 | */
29 | private SliceConfig sliceConfig = new SliceConfig();
30 |
31 | public void init() {
32 | this.sliceConfig.init();
33 | basePath = OssPathUtil.valid(basePath);
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/baidu/model/BaiduOssConfig.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.baidu.model;
2 |
3 | import io.github.artislong.model.SliceConfig;
4 | import io.github.artislong.utils.OssPathUtil;
5 | import lombok.Data;
6 | import lombok.extern.slf4j.Slf4j;
7 |
8 | import java.util.Optional;
9 |
10 | /**
11 | * @author 陈敏
12 | * @version BaiduOssConfig.java, v 1.1 2022/2/19 18:25 chenmin Exp $
13 | * Created on 2022/2/19
14 | */
15 | @Slf4j
16 | @Data
17 | public class BaiduOssConfig {
18 |
19 | private String basePath;
20 | private String bucketName;
21 | private String accessKeyId;
22 | private String secretAccessKey;
23 |
24 | private BaiduOssClientConfig clientConfig;
25 |
26 | /**
27 | * 断点续传参数
28 | */
29 | private SliceConfig sliceConfig = new SliceConfig();
30 |
31 | public void init() {
32 | this.sliceConfig.init();
33 | basePath = OssPathUtil.valid(basePath);
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/resources/jdbc/schema-mysql.sql:
--------------------------------------------------------------------------------
1 | # DROP TABLE OSS_STORE;
2 | # DROP TABLE OSS_DATA;
3 |
4 | CREATE TABLE OSS_STORE
5 | (
6 | ID VARCHAR(50) PRIMARY KEY COMMENT '主键',
7 | NAME VARCHAR(100) NOT NULL COMMENT '文件/目录名',
8 | PATH VARCHAR(500) NOT NULL COMMENT '路径',
9 | LENGTH LONG COMMENT '文件大小',
10 | CREATE_TIME DATETIME COMMENT '创建时间',
11 | LAST_UPDATE_TIME DATETIME COMMENT '最新修改时间',
12 | PARENT_ID VARCHAR(50) DEFAULT 0 COMMENT '父级目录ID',
13 | TYPE VARCHAR(2) NOT NULL COMMENT '类型(D:目录;F:文件)',
14 | DATA_ID VARCHAR(50) COMMENT '数据ID'
15 | ) COMMENT '对象存储';
16 |
17 | CREATE INDEX OSS_STORE_NAME_INDEX ON OSS_STORE (NAME);
18 | CREATE INDEX OSS_STORE_PATH_INDEX ON OSS_STORE (PATH);
19 | CREATE INDEX OSS_STORE_PARENT_INDEX ON OSS_STORE (PARENT_ID);
20 |
21 | CREATE TABLE OSS_DATA
22 | (
23 | ID VARCHAR(50) PRIMARY KEY COMMENT '主键',
24 | DATA LONGBLOB COMMENT '数据'
25 | ) COMMENT '数据';
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/ftp/model/FtpOssClientConfig.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.ftp.model;
2 |
3 | import cn.hutool.extra.ftp.FtpMode;
4 | import lombok.Data;
5 | import lombok.experimental.Accessors;
6 |
7 | /**
8 | * @author 陈敏
9 | * @version FtpOssClientConfig.java, v 1.0 2022/4/25 17:26 chenmin Exp $
10 | * Created on 2022/4/25
11 | */
12 | @Data
13 | @Accessors(chain = true)
14 | public class FtpOssClientConfig {
15 | /**
16 | * FTP连接模式,默认被动
17 | */
18 | private FtpMode mode = FtpMode.Passive;
19 | /**
20 | * 设置执行完操作是否返回当前目录,默认false
21 | */
22 | private boolean backToPwd = false;
23 | /**
24 | * 连接超时时长,单位毫秒
25 | */
26 | private long connectionTimeout;
27 | /**
28 | * Socket连接超时时长,单位毫秒
29 | */
30 | private long soTimeout;
31 | /**
32 | * 设置服务器语言
33 | */
34 | private String serverLanguageCode;
35 | /**
36 | * 设置服务器系统关键词
37 | */
38 | private String systemKey;
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/up/constant/ApiDomain.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.up.constant;
2 |
3 | import com.upyun.RestManager;
4 |
5 | /**
6 | * @author 陈敏
7 | * @version ApiDomain.java, v 1.1 2022/2/18 14:19 chenmin Exp $
8 | * Created on 2022/2/18
9 | */
10 | public enum ApiDomain {
11 | /**
12 | * 根据网络条件自动选择接入点:v0.api.upyun.com
13 | */
14 | ED_AUTO(RestManager.ED_AUTO),
15 | /**
16 | * 电信接入点:v1.api.upyun.com
17 | */
18 | ED_TELECOM(RestManager.ED_TELECOM),
19 | /**
20 | * 联通网通接入点:v2.api.upyun.com
21 | */
22 | ED_CNC(RestManager.ED_CNC),
23 | /**
24 | * 移动铁通接入点:v3.api.upyun.com
25 | */
26 | ED_CTT(RestManager.ED_CTT);
27 |
28 | private final String value;
29 |
30 | ApiDomain(String value) {
31 | this.value = value;
32 | }
33 |
34 | public String getValue() {
35 | return value;
36 | }
37 |
38 | @Override
39 | public String toString() {
40 | return value;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/pingan/model/PingAnOssConfig.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.pingan.model;
2 |
3 | import io.github.artislong.model.SliceConfig;
4 | import io.github.artislong.utils.OssPathUtil;
5 | import lombok.Data;
6 |
7 | /**
8 | * @author 陈敏
9 | * @version PingAnOssConfig.java, v 1.1 2022/3/8 10:26 chenmin Exp $
10 | * Created on 2022/3/8
11 | */
12 | @Data
13 | public class PingAnOssConfig {
14 |
15 | private String userAgent;
16 | private String obsUrl;
17 | private String obsAccessKey;
18 | private String obsSecret;
19 |
20 | private String userId;
21 |
22 | private String basePath;
23 | private String bucketName;
24 |
25 | private Boolean representPathInKey = false;
26 | private String domainName;
27 |
28 | /**
29 | * 断点续传参数
30 | */
31 | private SliceConfig sliceConfig = new SliceConfig();
32 |
33 | public void init() {
34 | this.sliceConfig.init();
35 | basePath = OssPathUtil.valid(basePath);
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/model/download/DownloadPartResult.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.model.download;
2 |
3 | import lombok.Data;
4 |
5 | /**
6 | * @author 陈敏
7 | * @version PartResult.java, v 1.1 2022/2/21 15:17 chenmin Exp $
8 | * Created on 2022/2/21
9 | */
10 | @Data
11 | public class DownloadPartResult {
12 |
13 | private int number;
14 | private long start;
15 | private long end;
16 | private boolean failed = false;
17 | private Exception exception;
18 | private Long clientCrc;
19 | private Long serverCrc;
20 | private long length;
21 |
22 | public DownloadPartResult(int number, long start, long end) {
23 | this.number = number;
24 | this.start = start;
25 | this.end = end;
26 | }
27 |
28 | public DownloadPartResult(int number, long start, long end, long length, long clientCrc) {
29 | this.number = number;
30 | this.start = start;
31 | this.end = end;
32 | this.length = length;
33 | this.clientCrc = clientCrc;
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/qingyun/model/QingYunOssConfig.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.qingyun.model;
2 |
3 | import io.github.artislong.core.qingyun.constant.QingYunOssConstant;
4 | import io.github.artislong.model.SliceConfig;
5 | import io.github.artislong.utils.OssPathUtil;
6 | import lombok.Data;
7 |
8 | /**
9 | * @author 陈敏
10 | * @version QingYunOssConfig.java, v 1.0 2022/3/10 23:53 chenmin Exp $
11 | * Created on 2022/3/10
12 | */
13 | @Data
14 | public class QingYunOssConfig {
15 |
16 | private String endpoint = QingYunOssConstant.DEFAULT_ENDPOINT;
17 | private String accessKey;
18 | private String accessSecret;
19 |
20 | private String bucketName;
21 | private String zone;
22 | private String basePath;
23 |
24 | private QingYunOssClientConfig clientConfig;
25 |
26 | /**
27 | * 断点续传参数
28 | */
29 | private SliceConfig sliceConfig = new SliceConfig();
30 |
31 | public void init() {
32 | this.sliceConfig.init();
33 | basePath = OssPathUtil.valid(basePath);
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/model/download/DownloadObjectStat.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.model.download;
2 |
3 | import lombok.Data;
4 | import lombok.experimental.Accessors;
5 |
6 | import java.io.Serializable;
7 | import java.util.Date;
8 |
9 | /**
10 | * @author 陈敏
11 | * @version ObjectStat.java, v 1.1 2022/2/21 15:15 chenmin Exp $
12 | * Created on 2022/2/21
13 | */
14 | @Data
15 | @Accessors(chain = true)
16 | public class DownloadObjectStat implements Serializable {
17 |
18 | private static final long serialVersionUID = -2883494783412999919L;
19 |
20 | private long size;
21 | private Date lastModified;
22 | private String digest;
23 |
24 | @Override
25 | public int hashCode() {
26 | final int prime = 31;
27 | int result = 1;
28 | result = prime * result + ((digest == null) ? 0 : digest.hashCode());
29 | result = prime * result + ((lastModified == null) ? 0 : lastModified.hashCode());
30 | result = prime * result + (int) (size ^ (size >>> 32));
31 | return result;
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/huawei/model/HuaweiOssConfig.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.huawei.model;
2 |
3 | import io.github.artislong.model.SliceConfig;
4 | import io.github.artislong.utils.OssPathUtil;
5 | import lombok.Data;
6 | import lombok.extern.slf4j.Slf4j;
7 |
8 | /**
9 | * @author 陈敏
10 | * @version HuaweiOssConfig.java, v 1.1 2022/2/19 18:33 chenmin Exp $
11 | * Created on 2022/2/19
12 | */
13 | @Slf4j
14 | @Data
15 | public class HuaweiOssConfig {
16 |
17 | private String basePath;
18 |
19 | private String accessKey;
20 | private String secretKey;
21 | /**
22 | * 连接OBS的服务地址。可包含协议类型、域名、端口号。示例:https://your-endpoint:443。
23 | * (出于安全性考虑,建议使用https协议)
24 | */
25 | private String endPoint;
26 | private String bucketName;
27 |
28 | private HuaweiOssClientConfig clientConfig;
29 |
30 | /**
31 | * 断点续传参数
32 | */
33 | private SliceConfig sliceConfig = new SliceConfig();
34 |
35 | public void init() {
36 | this.sliceConfig.init();
37 | basePath = OssPathUtil.valid(basePath);
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/src/test/java/io/github/artislong/core/ftp/FtpOssClientTest.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.ftp;
import io.github.artislong.core.StandardOssClient;
import io.github.artislong.core.StandardOssClientTest;
import lombok.Getter;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
@EnableAutoConfiguration(exclude = DataSourceAutoConfiguration.class)
public class FtpOssClientTest implements StandardOssClientTest {
@Getter
@Autowired
@Qualifier(FtpOssConfiguration.DEFAULT_BEAN_NAME)
private StandardOssClient ossClient;
@Test
public void test() throws Exception {
upLoad();
downLoad();
copy();
rename();
move();
isExist();
getInfo();
delete();
upLoadCheckPoint();
downloadCheckPoint();
}
}
--------------------------------------------------------------------------------
/src/test/java/io/github/artislong/core/wangyi/WangYiOssClientTest.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.wangyi;
import io.github.artislong.core.StandardOssClient;
import io.github.artislong.core.StandardOssClientTest;
import lombok.Getter;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
@EnableAutoConfiguration(exclude = DataSourceAutoConfiguration.class)
public class WangYiOssClientTest implements StandardOssClientTest {
@Getter
@Autowired
@Qualifier(WangYiOssConfiguration.DEFAULT_BEAN_NAME)
private StandardOssClient ossClient;
@Test
public void test() throws Exception {
upLoad();
downLoad();
copy();
rename();
move();
isExist();
getInfo();
delete();
upLoadCheckPoint();
downloadCheckPoint();
}
}
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/model/SliceConfig.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.model;
2 |
3 | import io.github.artislong.constant.OssConstant;
4 | import lombok.AllArgsConstructor;
5 | import lombok.Data;
6 | import lombok.NoArgsConstructor;
7 | import lombok.extern.slf4j.Slf4j;
8 |
9 | /**
10 | * 断点续传参数
11 | * @author 陈敏
12 | * @version Slice.java, v 1.1 2022/2/10 17:09 chenmin Exp $
13 | * Created on 2022/2/10
14 | */
15 | @Slf4j
16 | @Data
17 | @AllArgsConstructor
18 | @NoArgsConstructor
19 | public class SliceConfig {
20 | /**
21 | * 分片大小,默认5MB
22 | */
23 | private Long partSize = OssConstant.DEFAULT_PART_SIZE;
24 |
25 | /**
26 | * 并发线程数,默认等于CPU的核数
27 | */
28 | private Integer taskNum = OssConstant.DEFAULT_TASK_NUM;
29 |
30 | public void init() {
31 | if (this.getPartSize() <= 0) {
32 | log.warn("断点续传——分片大小必须大于0");
33 | this.setPartSize(OssConstant.DEFAULT_PART_SIZE);
34 | }
35 | if (this.getTaskNum() <= 0) {
36 | log.warn("断点续传——并发线程数必须大于0");
37 | this.setTaskNum(OssConstant.DEFAULT_TASK_NUM);
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/resources/META-INF/spring.factories:
--------------------------------------------------------------------------------
1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
2 | io.github.artislong.OssAutoConfiguration,\
3 | io.github.artislong.core.ali.AliOssConfiguration,\
4 | io.github.artislong.core.baidu.BaiduOssConfiguration,\
5 | io.github.artislong.core.ftp.FtpOssConfiguration,\
6 | io.github.artislong.core.huawei.HuaWeiOssConfiguration,\
7 | io.github.artislong.core.jd.JdOssConfiguration,\
8 | io.github.artislong.core.jdbc.JdbcOssConfiguration,\
9 | io.github.artislong.core.jinshan.JinShanOssConfiguration,\
10 | io.github.artislong.core.local.LocalOssConfiguration,\
11 | io.github.artislong.core.minio.MinioOssConfiguration,\
12 | io.github.artislong.core.pingan.PingAnOssConfiguration,\
13 | io.github.artislong.core.qingyun.QingYunOssConfiguration,\
14 | io.github.artislong.core.qiniu.QiNiuOssConfiguration,\
15 | io.github.artislong.core.sftp.SftpOssConfiguration,\
16 | io.github.artislong.core.tencent.TencentOssConfiguration,\
17 | io.github.artislong.core.ucloud.UCloudOssConfiguration,\
18 | io.github.artislong.core.up.UpOssConfiguration,\
19 | io.github.artislong.core.wangyi.WangYiOssConfiguration
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/aws/model/AwsOssConfig.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.aws.model;
2 |
3 | import io.github.artislong.core.aws.constant.AwsRegion;
4 | import io.github.artislong.model.SliceConfig;
5 | import io.github.artislong.utils.OssPathUtil;
6 | import lombok.Data;
7 | import software.amazon.awssdk.awscore.defaultsmode.DefaultsMode;
8 |
9 | /**
10 | * @author 陈敏
11 | * @version AwsOssConfig.java, v 1.0 2022/4/1 18:05 chenmin Exp $
12 | * Created on 2022/4/1
13 | */
14 | @Data
15 | public class AwsOssConfig {
16 | /**
17 | * 数据存储路径
18 | */
19 | private String basePath;
20 | /**
21 | * Bucket名称
22 | */
23 | private String bucketName;
24 |
25 | private String accessKeyId;
26 |
27 | private String secretAccessKey;
28 |
29 | private AwsRegion region;
30 |
31 | private DefaultsMode mode;
32 |
33 | private AwsOssClientConfig clientConfig;
34 | /**
35 | * 断点续传参数
36 | */
37 | private SliceConfig sliceConfig = new SliceConfig();
38 |
39 | public void init() {
40 | this.sliceConfig.init();
41 | basePath = OssPathUtil.valid(basePath);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/jd/JdOssProperties.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.jd;
2 |
3 | import cn.hutool.core.text.CharPool;
4 | import io.github.artislong.constant.OssConstant;
5 | import io.github.artislong.core.jd.model.JdOssConfig;
6 | import lombok.Data;
7 | import org.springframework.beans.factory.InitializingBean;
8 | import org.springframework.boot.context.properties.ConfigurationProperties;
9 |
10 | import java.util.HashMap;
11 | import java.util.Map;
12 |
13 | /**
14 | * @author 陈敏
15 | * @version JdOssProperties.java, v 1.1 2021/11/25 10:44 chenmin Exp $
16 | * Created on 2021/11/25
17 | */
18 | @Data
19 | @ConfigurationProperties(OssConstant.OSS + CharPool.DOT + OssConstant.OssType.JD)
20 | public class JdOssProperties extends JdOssConfig implements InitializingBean {
21 |
22 | private Boolean enable = false;
23 |
24 | private Map ossConfig = new HashMap<>();
25 |
26 | @Override
27 | public void afterPropertiesSet() {
28 | if (ossConfig.isEmpty()) {
29 | this.init();
30 | } else {
31 | ossConfig.values().forEach(JdOssConfig::init);
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/ftp/FtpOssProperties.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.ftp;
2 |
3 | import cn.hutool.core.text.CharPool;
4 | import io.github.artislong.constant.OssConstant;
5 | import io.github.artislong.core.ftp.model.FtpOssConfig;
6 | import lombok.Data;
7 | import org.springframework.beans.factory.InitializingBean;
8 | import org.springframework.boot.context.properties.ConfigurationProperties;
9 |
10 | import java.util.HashMap;
11 | import java.util.Map;
12 |
13 | /**
14 | * @author 陈敏
15 | * @version FtpOssProperties.java, v 1.1 2021/11/16 15:29 chenmin Exp $
16 | * Created on 2021/11/16
17 | */
18 | @Data
19 | @ConfigurationProperties(OssConstant.OSS + CharPool.DOT + OssConstant.OssType.FTP)
20 | public class FtpOssProperties extends FtpOssConfig implements InitializingBean {
21 |
22 | private Boolean enable = false;
23 |
24 | private Map ossConfig = new HashMap<>();
25 |
26 | @Override
27 | public void afterPropertiesSet() {
28 | if (ossConfig.isEmpty()) {
29 | this.init();
30 | } else {
31 | ossConfig.values().forEach(FtpOssConfig::init);
32 | }
33 | }
34 | }
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/up/UpOssProperties.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.up;
2 |
3 | import cn.hutool.core.text.CharPool;
4 | import io.github.artislong.constant.OssConstant;
5 | import io.github.artislong.core.up.model.UpOssConfig;
6 | import lombok.Data;
7 | import org.springframework.beans.factory.InitializingBean;
8 | import org.springframework.boot.context.properties.ConfigurationProperties;
9 |
10 | import java.util.HashMap;
11 | import java.util.Map;
12 |
13 | /**
14 | * @author 陈敏
15 | * @version UpOssProperties.java, v 1.1 2021/11/30 12:03 chenmin Exp $
16 | * Created on 2021/11/30
17 | */
18 | @Data
19 | @ConfigurationProperties(OssConstant.OSS + CharPool.DOT + OssConstant.OssType.UP)
20 | public class UpOssProperties extends UpOssConfig implements InitializingBean {
21 |
22 | private Boolean enable = false;
23 |
24 | private Map ossConfig = new HashMap<>();
25 |
26 | @Override
27 | public void afterPropertiesSet() {
28 | if (ossConfig.isEmpty()) {
29 | this.init();
30 | } else {
31 | ossConfig.values().forEach(UpOssConfig::init);
32 | }
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/jdbc/JdbcOssProperties.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.jdbc;
2 |
3 | import cn.hutool.core.text.CharPool;
4 | import io.github.artislong.constant.OssConstant;
5 | import io.github.artislong.core.jdbc.model.JdbcOssConfig;
6 | import lombok.Data;
7 | import org.springframework.beans.factory.InitializingBean;
8 | import org.springframework.boot.context.properties.ConfigurationProperties;
9 |
10 | import java.util.HashMap;
11 | import java.util.Map;
12 |
13 | /**
14 | * @author 陈敏
15 | * @version JdbcOssProperties.java, v 1.0 2022/3/11 21:36 chenmin Exp $
16 | * Created on 2022/3/11
17 | */
18 | @Data
19 | @ConfigurationProperties(OssConstant.OSS + CharPool.DOT + OssConstant.OssType.JDBC)
20 | public class JdbcOssProperties extends JdbcOssConfig implements InitializingBean {
21 | private Boolean enable = false;
22 |
23 | private Map ossConfig = new HashMap<>();
24 |
25 | @Override
26 | public void afterPropertiesSet() {
27 | if (ossConfig.isEmpty()) {
28 | this.init();
29 | } else {
30 | ossConfig.values().forEach(JdbcOssConfig::init);
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/test/java/io/github/artislong/core/aws/AwsOssClientTest.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.aws;
2 |
3 | import io.github.artislong.core.StandardOssClient;
4 | import io.github.artislong.core.StandardOssClientTest;
5 | import lombok.Getter;
6 | import org.junit.jupiter.api.Test;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.beans.factory.annotation.Qualifier;
9 | import org.springframework.boot.test.context.SpringBootTest;
10 |
11 | /**
12 | * @author 陈敏
13 | * @version AwsOssClientTest.java, v 1.0 2022/4/2 20:58 chenmin Exp $
14 | * Created on 2022/4/2
15 | */
16 | @SpringBootTest
17 | public class AwsOssClientTest implements StandardOssClientTest {
18 |
19 | @Getter
20 | @Autowired
21 | @Qualifier(AwsOssConfiguration.DEFAULT_BEAN_NAME)
22 | private StandardOssClient ossClient;
23 |
24 | @Test
25 | public void test() throws Exception {
26 | upLoad();
27 | downLoad();
28 | copy();
29 | rename();
30 | move();
31 | isExist();
32 | getInfo();
33 | delete();
34 |
35 | upLoadCheckPoint();
36 | downloadCheckPoint();
37 | }
38 |
39 | }
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/local/LocalOssProperties.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.local;
2 |
3 | import cn.hutool.core.text.CharPool;
4 | import io.github.artislong.constant.OssConstant;
5 | import io.github.artislong.core.local.model.LocalOssConfig;
6 | import lombok.Data;
7 | import org.springframework.beans.factory.InitializingBean;
8 | import org.springframework.boot.context.properties.ConfigurationProperties;
9 |
10 | import java.util.HashMap;
11 | import java.util.Map;
12 |
13 | /**
14 | * @author 陈敏
15 | * @version LocalProperties.java, v 1.1 2022/2/11 15:28 chenmin Exp $
16 | * Created on 2022/2/11
17 | */
18 | @Data
19 | @ConfigurationProperties(OssConstant.OSS + CharPool.DOT + OssConstant.OssType.LOCAL)
20 | public class LocalOssProperties extends LocalOssConfig implements InitializingBean {
21 |
22 | private Boolean enable = false;
23 |
24 | private Map ossConfig = new HashMap<>();
25 |
26 | @Override
27 | public void afterPropertiesSet() {
28 | if (ossConfig.isEmpty()) {
29 | this.init();
30 | } else {
31 | ossConfig.values().forEach(LocalOssConfig::init);
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/minio/MinioOssProperties.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.minio;
2 |
3 | import cn.hutool.core.text.CharPool;
4 | import io.github.artislong.constant.OssConstant;
5 | import io.github.artislong.core.minio.model.MinioOssConfig;
6 | import lombok.Data;
7 | import org.springframework.beans.factory.InitializingBean;
8 | import org.springframework.boot.context.properties.ConfigurationProperties;
9 |
10 | import java.util.HashMap;
11 | import java.util.Map;
12 |
13 | /**
14 | * @author 陈敏
15 | * @version MinioProperties.java, v 1.1 2021/11/24 15:20 chenmin Exp $
16 | * Created on 2021/11/24
17 | */
18 | @Data
19 | @ConfigurationProperties(OssConstant.OSS + CharPool.DOT + OssConstant.OssType.MINIO)
20 | public class MinioOssProperties extends MinioOssConfig implements InitializingBean {
21 |
22 | private Boolean enable = false;
23 |
24 | private Map ossConfig = new HashMap<>();
25 |
26 | @Override
27 | public void afterPropertiesSet() {
28 | if (ossConfig.isEmpty()) {
29 | this.init();
30 | } else {
31 | ossConfig.values().forEach(MinioOssConfig::init);
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/sftp/SftpOssProperties.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.sftp;
2 |
3 | import cn.hutool.core.text.CharPool;
4 | import io.github.artislong.constant.OssConstant;
5 | import io.github.artislong.core.sftp.model.SftpOssConfig;
6 | import lombok.Data;
7 | import org.springframework.beans.factory.InitializingBean;
8 | import org.springframework.boot.context.properties.ConfigurationProperties;
9 |
10 | import java.util.HashMap;
11 | import java.util.Map;
12 |
13 | /**
14 | * @author 陈敏
15 | * @version SftpOssProperties.java, v 1.1 2021/11/16 15:32 chenmin Exp $
16 | * Created on 2021/11/16
17 | */
18 | @Data
19 | @ConfigurationProperties(OssConstant.OSS + CharPool.DOT + OssConstant.OssType.SFTP)
20 | public class SftpOssProperties extends SftpOssConfig implements InitializingBean {
21 |
22 | private Boolean enable = false;
23 |
24 | private Map ossConfig = new HashMap<>();
25 |
26 | @Override
27 | public void afterPropertiesSet() {
28 | if (ossConfig.isEmpty()) {
29 | this.init();
30 | } else {
31 | ossConfig.values().forEach(SftpOssConfig::init);
32 | }
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/qiniu/QiNiuOssProperties.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.qiniu;
2 |
3 | import cn.hutool.core.text.CharPool;
4 | import io.github.artislong.constant.OssConstant;
5 | import io.github.artislong.core.qiniu.model.QiNiuOssConfig;
6 | import lombok.Data;
7 | import org.springframework.beans.factory.InitializingBean;
8 | import org.springframework.boot.context.properties.ConfigurationProperties;
9 |
10 | import java.util.HashMap;
11 | import java.util.Map;
12 |
13 | /**
14 | * @author 陈敏
15 | * @version QiNiuOssProperties.java, v 1.1 2021/11/16 15:30 chenmin Exp $
16 | * Created on 2021/11/16
17 | */
18 | @Data
19 | @ConfigurationProperties(OssConstant.OSS + CharPool.DOT + OssConstant.OssType.QINIU)
20 | public class QiNiuOssProperties extends QiNiuOssConfig implements InitializingBean {
21 |
22 | private Boolean enable = false;
23 |
24 | private Map ossConfig = new HashMap<>();
25 |
26 | @Override
27 | public void afterPropertiesSet() {
28 | if (ossConfig.isEmpty()) {
29 | this.init();
30 | } else {
31 | ossConfig.values().forEach(QiNiuOssConfig::init);
32 | }
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/ucloud/UCloudOssProperties.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.ucloud;
2 |
3 | import cn.hutool.core.text.CharPool;
4 | import io.github.artislong.constant.OssConstant;
5 | import io.github.artislong.core.ucloud.model.UCloudOssConfig;
6 | import lombok.Data;
7 | import org.springframework.beans.factory.InitializingBean;
8 | import org.springframework.boot.context.properties.ConfigurationProperties;
9 |
10 | import java.util.HashMap;
11 | import java.util.Map;
12 |
13 | /**
14 | * @author 陈敏
15 | * @version UCloudOssProperties.java, v 1.1 2022/3/7 0:20 chenmin Exp $
16 | * Created on 2022/3/7
17 | */
18 | @Data
19 | @ConfigurationProperties(OssConstant.OSS + CharPool.DOT + OssConstant.OssType.UCLOUD)
20 | public class UCloudOssProperties extends UCloudOssConfig implements InitializingBean {
21 |
22 | private Boolean enable = false;
23 |
24 | private Map ossConfig = new HashMap<>();
25 |
26 | @Override
27 | public void afterPropertiesSet() {
28 | if (ossConfig.isEmpty()) {
29 | this.init();
30 | } else {
31 | ossConfig.values().forEach(UCloudOssConfig::init);
32 | }
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/pingan/PingAnOssProperties.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.pingan;
2 |
3 | import cn.hutool.core.text.CharPool;
4 | import io.github.artislong.constant.OssConstant;
5 | import io.github.artislong.core.pingan.model.PingAnOssConfig;
6 | import lombok.Data;
7 | import org.springframework.beans.factory.InitializingBean;
8 | import org.springframework.boot.context.properties.ConfigurationProperties;
9 |
10 | import java.util.HashMap;
11 | import java.util.Map;
12 |
13 | /**
14 | * @author 陈敏
15 | * @version PingAnOssProperties.java, v 1.1 2022/3/8 10:26 chenmin Exp $
16 | * Created on 2022/3/8
17 | */
18 | @Data
19 | @ConfigurationProperties(OssConstant.OSS + CharPool.DOT + OssConstant.OssType.PINGAN)
20 | public class PingAnOssProperties extends PingAnOssConfig implements InitializingBean {
21 |
22 | private Boolean enable = false;
23 |
24 | private Map ossConfig = new HashMap<>();
25 |
26 | @Override
27 | public void afterPropertiesSet() {
28 | if (ossConfig.isEmpty()) {
29 | this.init();
30 | } else {
31 | ossConfig.values().forEach(PingAnOssConfig::init);
32 | }
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/jinshan/JinShanOssProperties.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.jinshan;
2 |
3 | import cn.hutool.core.text.CharPool;
4 | import io.github.artislong.constant.OssConstant;
5 | import io.github.artislong.core.jinshan.model.JinShanOssConfig;
6 | import lombok.Data;
7 | import org.springframework.beans.factory.InitializingBean;
8 | import org.springframework.boot.context.properties.ConfigurationProperties;
9 |
10 | import java.util.HashMap;
11 | import java.util.Map;
12 |
13 | /**
14 | * @author 陈敏
15 | * @version JinShanOssProperties.java, v 1.1 2022/3/3 22:10 chenmin Exp $
16 | * Created on 2022/3/3
17 | */
18 | @Data
19 | @ConfigurationProperties(OssConstant.OSS + CharPool.DOT + OssConstant.OssType.JINSHAN)
20 | public class JinShanOssProperties extends JinShanOssConfig implements InitializingBean {
21 |
22 | private Boolean enable = false;
23 |
24 | private Map ossConfig = new HashMap<>();
25 |
26 | @Override
27 | public void afterPropertiesSet() {
28 | if (ossConfig.isEmpty()) {
29 | this.init();
30 | } else {
31 | ossConfig.values().forEach(JinShanOssConfig::init);
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/qingyun/QingYunOssProperties.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.qingyun;
2 |
3 | import cn.hutool.core.text.CharPool;
4 | import io.github.artislong.constant.OssConstant;
5 | import io.github.artislong.core.qingyun.model.QingYunOssConfig;
6 | import lombok.Data;
7 | import org.springframework.beans.factory.InitializingBean;
8 | import org.springframework.boot.context.properties.ConfigurationProperties;
9 |
10 | import java.util.HashMap;
11 | import java.util.Map;
12 |
13 | /**
14 | * @author 陈敏
15 | * @version QingYunOssProperties.java, v 1.0 2022/3/10 23:52 chenmin Exp $
16 | * Created on 2022/3/10
17 | */
18 | @Data
19 | @ConfigurationProperties(OssConstant.OSS + CharPool.DOT + OssConstant.OssType.QINGYUN)
20 | public class QingYunOssProperties extends QingYunOssConfig implements InitializingBean {
21 |
22 | private Boolean enable = false;
23 |
24 | private Map ossConfig = new HashMap<>();
25 |
26 | @Override
27 | public void afterPropertiesSet() {
28 | if (ossConfig.isEmpty()) {
29 | this.init();
30 | } else {
31 | ossConfig.values().forEach(QingYunOssConfig::init);
32 | }
33 | }
34 |
35 | }
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/tencent/TencentOssProperties.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.tencent;
2 |
3 | import cn.hutool.core.text.CharPool;
4 | import io.github.artislong.constant.OssConstant;
5 | import io.github.artislong.core.tencent.model.TencentOssConfig;
6 | import lombok.Data;
7 | import org.springframework.beans.factory.InitializingBean;
8 | import org.springframework.boot.context.properties.ConfigurationProperties;
9 |
10 | import java.util.HashMap;
11 | import java.util.Map;
12 |
13 | /**
14 | * @author 陈敏
15 | * @version TencentProperties.java, v 1.1 2021/11/24 15:22 chenmin Exp $
16 | * Created on 2021/11/24
17 | */
18 | @Data
19 | @ConfigurationProperties(OssConstant.OSS + CharPool.DOT + OssConstant.OssType.TENCENT)
20 | public class TencentOssProperties extends TencentOssConfig implements InitializingBean {
21 |
22 | private Boolean enable = false;
23 |
24 | private Map ossConfig = new HashMap<>();
25 |
26 | @Override
27 | public void afterPropertiesSet() {
28 | if (ossConfig.isEmpty()) {
29 | this.init();
30 | } else {
31 | ossConfig.values().forEach(TencentOssConfig::init);
32 | }
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/model/download/DownloadPart.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.model.download;
2 |
3 | import lombok.Data;
4 |
5 | import java.io.Serializable;
6 |
7 | /**
8 | * @author 陈敏
9 | * @version DownloadPart.java, v 1.1 2022/2/21 15:15 chenmin Exp $
10 | * Created on 2022/2/21
11 | */
12 | @Data
13 | public class DownloadPart implements Serializable {
14 |
15 | private static final long serialVersionUID = -3655925846487976207L;
16 |
17 | private int index;
18 | private long start;
19 | private long end;
20 | private boolean isCompleted;
21 | private long length;
22 | private long crc;
23 | private long fileStart;
24 |
25 | @Override
26 | public int hashCode() {
27 | final int prime = 31;
28 | int result = 1;
29 | result = prime * result + index;
30 | result = prime * result + (isCompleted ? 1231 : 1237);
31 | result = prime * result + (int) (end ^ (end >>> 32));
32 | result = prime * result + (int) (start ^ (start >>> 32));
33 | result = prime * result + (int) (crc ^ (crc >>> 32));
34 | result = prime * result + (int) (fileStart ^ (fileStart >>> 32));
35 | return result;
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/wangyi/WangYiOssProperties.java:
--------------------------------------------------------------------------------
1 | /**
* $Id: WangYiOssProperties.java,v 1.0 2022/3/4 9:51 PM chenmin Exp $
*/
package io.github.artislong.core.wangyi;
import cn.hutool.core.text.CharPool;
import io.github.artislong.constant.OssConstant;
import io.github.artislong.core.tencent.model.TencentOssConfig;
import io.github.artislong.core.wangyi.model.WangYiOssConfig;
import lombok.Data;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import java.util.HashMap;
import java.util.Map;
/**
* @author 陈敏
* @version $Id: WangYiOssProperties.java,v 1.1 2022/3/4 9:51 PM chenmin Exp $
* Created on 2022/3/4 9:51 PM
* My blog: https://www.chenmin.info
*/
@Data
@ConfigurationProperties(OssConstant.OSS + CharPool.DOT + OssConstant.OssType.WANGYI)
public class WangYiOssProperties extends WangYiOssConfig implements InitializingBean {
private Boolean enable = false;
private Map ossConfig = new HashMap<>();
@Override
public void afterPropertiesSet() {
if (ossConfig.isEmpty()) {
this.init();
} else {
ossConfig.values().forEach(WangYiOssConfig::init);
}
}
}
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/ali/model/AliOssConfig.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.ali.model;
2 |
3 | import io.github.artislong.model.SliceConfig;
4 | import io.github.artislong.utils.OssPathUtil;
5 | import lombok.Data;
6 | import lombok.EqualsAndHashCode;
7 |
8 | /**
9 | * @author 陈敏
10 | * @version AliGroupInfo.java, v 1.1 2022/2/18 17:48 chenmin Exp $
11 | * Created on 2022/2/18
12 | */
13 | @Data
14 | @EqualsAndHashCode
15 | public class AliOssConfig {
16 | /**
17 | * 数据存储路径
18 | */
19 | private String basePath;
20 | /**
21 | * Bucket名称
22 | */
23 | private String bucketName;
24 | /**
25 | * OSS地址
26 | */
27 | private String endpoint;
28 | /**
29 | * AccessKey ID
30 | */
31 | private String accessKeyId;
32 | /**
33 | * AccessKey Secret
34 | */
35 | private String accessKeySecret;
36 |
37 | private String securityToken;
38 |
39 | private AliOssClientConfig clientConfig;
40 |
41 | /**
42 | * 断点续传参数
43 | */
44 | private SliceConfig sliceConfig = new SliceConfig();
45 |
46 | public void init() {
47 | this.sliceConfig.init();
48 | basePath = OssPathUtil.valid(basePath);
49 | }
50 |
51 | }
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/baidu/BaiduOssProperties.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.baidu;
2 |
3 | import cn.hutool.core.text.CharPool;
4 | import io.github.artislong.constant.OssConstant;
5 | import io.github.artislong.core.baidu.model.BaiduOssConfig;
6 | import lombok.Data;
7 | import lombok.extern.slf4j.Slf4j;
8 | import org.springframework.beans.factory.InitializingBean;
9 | import org.springframework.boot.context.properties.ConfigurationProperties;
10 |
11 | import java.util.HashMap;
12 | import java.util.Map;
13 |
14 | /**
15 | * @author 陈敏
16 | * @version BaiduProperties.java, v 1.1 2021/11/24 15:26 chenmin Exp $
17 | * Created on 2021/11/24
18 | */
19 | @Slf4j
20 | @Data
21 | @ConfigurationProperties(OssConstant.OSS + CharPool.DOT + OssConstant.OssType.BAIDU)
22 | public class BaiduOssProperties extends BaiduOssConfig implements InitializingBean {
23 |
24 | private Boolean enable = false;
25 |
26 | private Map ossConfig = new HashMap<>();
27 |
28 | @Override
29 | public void afterPropertiesSet() {
30 | if (ossConfig.isEmpty()) {
31 | this.init();
32 | } else {
33 | ossConfig.values().forEach(BaiduOssConfig::init);
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/aws/AwsOssProperties.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.aws;
2 |
3 | import cn.hutool.core.text.CharPool;
4 | import io.github.artislong.constant.OssConstant;
5 | import io.github.artislong.core.aws.model.AwsOssConfig;
6 | import lombok.Data;
7 | import lombok.EqualsAndHashCode;
8 | import org.springframework.beans.factory.InitializingBean;
9 | import org.springframework.boot.context.properties.ConfigurationProperties;
10 |
11 | import java.util.HashMap;
12 | import java.util.Map;
13 |
14 | /**
15 | * @author 陈敏
16 | * @version AwsOssProperties.java, v 1.0 2022/4/1 18:04 chenmin Exp $
17 | * Created on 2022/4/1
18 | */
19 | @Data
20 | @EqualsAndHashCode(callSuper = true)
21 | @ConfigurationProperties(OssConstant.OSS + CharPool.DOT + OssConstant.OssType.AWS)
22 | public class AwsOssProperties extends AwsOssConfig implements InitializingBean {
23 |
24 | private Boolean enable = false;
25 |
26 | private Map ossConfig = new HashMap<>();
27 |
28 | @Override
29 | public void afterPropertiesSet() {
30 | if (ossConfig.isEmpty()) {
31 | this.init();
32 | } else {
33 | ossConfig.values().forEach(AwsOssConfig::init);
34 | }
35 | }
36 |
37 | }
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/ali/AliOssProperties.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.ali;
2 |
3 | import cn.hutool.core.text.CharPool;
4 | import io.github.artislong.constant.OssConstant;
5 | import io.github.artislong.core.ali.model.AliOssConfig;
6 | import lombok.Data;
7 | import lombok.EqualsAndHashCode;
8 | import org.springframework.beans.factory.InitializingBean;
9 | import org.springframework.boot.context.properties.ConfigurationProperties;
10 |
11 | import java.util.HashMap;
12 | import java.util.Map;
13 |
14 | /**
15 | * @author 陈敏
16 | * @version AliOssProperties.java, v 1.1 2021/11/16 15:25 chenmin Exp $
17 | * Created on 2021/11/16
18 | */
19 | @Data
20 | @EqualsAndHashCode(callSuper = true)
21 | @ConfigurationProperties(OssConstant.OSS + CharPool.DOT + OssConstant.OssType.ALI)
22 | public class AliOssProperties extends AliOssConfig implements InitializingBean {
23 |
24 | private Boolean enable = false;
25 |
26 | private Map ossConfig = new HashMap<>();
27 |
28 | @Override
29 | public void afterPropertiesSet() {
30 | if (ossConfig.isEmpty()) {
31 | this.init();
32 | } else {
33 | ossConfig.values().forEach(AliOssConfig::init);
34 | }
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/huawei/HuaWeiOssProperties.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.huawei;
2 |
3 | import cn.hutool.core.text.CharPool;
4 | import io.github.artislong.constant.OssConstant;
5 | import io.github.artislong.core.huawei.model.HuaweiOssConfig;
6 | import lombok.Data;
7 | import lombok.extern.slf4j.Slf4j;
8 | import org.springframework.beans.factory.InitializingBean;
9 | import org.springframework.boot.context.properties.ConfigurationProperties;
10 |
11 | import java.util.HashMap;
12 | import java.util.Map;
13 |
14 | /**
15 | * @author 陈敏
16 | * @version HuaWeiOssProperties.java, v 1.1 2021/11/25 9:56 chenmin Exp $
17 | * Created on 2021/11/25
18 | */
19 | @Slf4j
20 | @Data
21 | @ConfigurationProperties(OssConstant.OSS + CharPool.DOT + OssConstant.OssType.HUAWEI)
22 | public class HuaWeiOssProperties extends HuaweiOssConfig implements InitializingBean {
23 |
24 | private Boolean enable = false;
25 |
26 | private Map ossConfig = new HashMap<>();
27 |
28 | @Override
29 | public void afterPropertiesSet() {
30 | if (ossConfig.isEmpty()) {
31 | this.init();
32 | } else {
33 | ossConfig.values().forEach(HuaweiOssConfig::init);
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/minio/model/MinioOssClientConfig.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.minio.model;
2 |
3 | import io.github.artislong.constant.OssConstant;
4 | import lombok.Data;
5 |
6 | /**
7 | * @author 陈敏
8 | * @version MinioOssClientConfig.java, v 1.0 2022/3/24 9:59 chenmin Exp $
9 | * Created on 2022/3/24
10 | */
11 | @Data
12 | public class MinioOssClientConfig {
13 | /**
14 | * 连接超时时间(单位:毫秒)
15 | */
16 | private Long connectTimeout = OssConstant.DEFAULT_CONNECTION_TIMEOUT;
17 | /**
18 | * 写超时时间(单位:毫秒)
19 | */
20 | private Long writeTimeout = OssConstant.DEFAULT_CONNECTION_TIMEOUT;
21 | /**
22 | * 读超时时间(单位:毫秒)
23 | */
24 | private Long readTimeout = OssConstant.DEFAULT_CONNECTION_TIMEOUT;
25 | /**
26 | * 调用超时时间(单位:毫秒)
27 | */
28 | private Long callTimeout = (long) Integer.MAX_VALUE;
29 | /**
30 | * 是否支持重定向,默认支持
31 | */
32 | private boolean followRedirects = true;
33 | /**
34 | * 是否支持HTTP到HTTPS,HTTPS到HTTP的重定向,默认支持
35 | */
36 | private boolean followSslRedirects = true;
37 | /**
38 | * 是否开始连接失败重试,默认不支持
39 | */
40 | private boolean retryOnConnectionFailure = false;
41 | /**
42 | * 连接健康检测间隔时长(单位:毫秒)
43 | */
44 | private int pingInterval;
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/model/upload/UploadPart.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.model.upload;
2 |
3 | import lombok.Data;
4 |
5 | import java.io.Serializable;
6 |
7 | /**
8 | * 分块
9 | * @author 陈敏
10 | * @version UploadPart.java, v 1.1 2022/2/9 23:01 chenmin Exp $
11 | * Created on 2022/2/9
12 | */
13 | @Data
14 | public class UploadPart implements Serializable {
15 |
16 | private static final long serialVersionUID = 6692863980224332199L;
17 |
18 | /**
19 | * 分块号(顺序)
20 | */
21 | private int number;
22 | /**
23 | * 分块在文件中的偏移量
24 | */
25 | private long offset;
26 | /**
27 | * 分块大小
28 | */
29 | private long size;
30 | /**
31 | * 分块成功标识
32 | */
33 | private boolean isCompleted = false;
34 | /**
35 | * 分块crc
36 | */
37 | private long crc;
38 |
39 | @Override
40 | public int hashCode() {
41 | final int prime = 31;
42 | int result = 1;
43 | result = prime * result + (isCompleted ? 1231 : 1237);
44 | result = prime * result + number;
45 | result = prime * result + (int) (offset ^ (offset >>> 32));
46 | result = prime * result + (int) (size ^ (size >>> 32));
47 | result = prime * result + (int) (crc ^ (crc >>> 32));
48 | return result;
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/qiniu/constant/QiNiuRegion.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.qiniu.constant;
2 |
3 | import cn.hutool.core.util.ReflectUtil;
4 | import com.qiniu.storage.Region;
5 |
6 | import java.lang.reflect.Method;
7 |
8 | /**
9 | * @author 陈敏
10 | * @version QiNiuRegion.java, v 1.1 2021/11/24 14:29 chenmin Exp $
11 | * Created on 2021/11/24
12 | */
13 | public enum QiNiuRegion {
14 | /**
15 | * 华东区域
16 | */
17 | HUADONG("huadong"),
18 | /**
19 | * 华北区域
20 | */
21 | HUABEI("huabei"),
22 | /**
23 | * 华南区域
24 | */
25 | HUANAN("huanan"),
26 | /**
27 | * 北美区域
28 | */
29 | BEIMEI("beimei"),
30 | /**
31 | * 新加坡区域
32 | */
33 | XINJIAPO("xinjiapo"),
34 | /**
35 | *
36 | */
37 | AUTOREGION("autoRegion");
38 |
39 | private final String region;
40 |
41 | QiNiuRegion(String region) {
42 | this.region = region;
43 | }
44 |
45 | public String getRegion() {
46 | return region;
47 | }
48 |
49 | @Override
50 | public String toString() {
51 | return region;
52 | }
53 |
54 | public Region buildRegion() {
55 | Method method = ReflectUtil.getMethodByName(Region.class, this.region);
56 | return ReflectUtil.invokeStatic(method);
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/model/upload/UpLoadPartResult.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.model.upload;
2 |
3 | import lombok.Data;
4 | import lombok.experimental.Accessors;
5 |
6 | /**
7 | * 分块结果集
8 | * @author 陈敏
9 | * @version PartResult.java, v 1.1 2022/2/10 10:01 chenmin Exp $
10 | * Created on 2022/2/10
11 | */
12 | @Accessors(chain = true)
13 | @Data
14 | public class UpLoadPartResult {
15 |
16 | /**
17 | * 分块号
18 | */
19 | private int number;
20 | /**
21 | * 分块在文件中的偏移量
22 | */
23 | private long offset;
24 | /**
25 | * 分块大小
26 | */
27 | private long length;
28 | /**
29 | * 分块失败标识
30 | */
31 | private boolean failed = false;
32 | /**
33 | * 分块上传失败异常
34 | */
35 | private Exception exception;
36 | /**
37 | * 分块crc
38 | */
39 | private Long partCrc;
40 |
41 | private UpLoadPartEntityTag entityTag;
42 |
43 | public UpLoadPartResult(int number, long offset, long length) {
44 | this.number = number;
45 | this.offset = offset;
46 | this.length = length;
47 | }
48 |
49 | public UpLoadPartResult(int number, long offset, long length, long partCrc) {
50 | this.number = number;
51 | this.offset = offset;
52 | this.length = length;
53 | this.partCrc = partCrc;
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/qingyun/model/QingYunOssClientConfig.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.qingyun.model;
2 |
3 | import com.qingstor.sdk.config.EnvContext;
4 | import lombok.Data;
5 | import lombok.experimental.Accessors;
6 |
7 | /**
8 | * @author 陈敏
9 | * @version QingYunOssClientConfig.java, v 1.0 2022/4/20 18:13 chenmin Exp $
10 | * Created on 2022/4/20
11 | */
12 | @Data
13 | @Accessors(chain = true)
14 | public class QingYunOssClientConfig {
15 | /**
16 | * 是否支持CNAME作为Endpoint,默认不支持CNAME。
17 | */
18 | private boolean cnameSupport = false;
19 | /**
20 | * 附加的用户代理
21 | */
22 | private String additionalUserAgent;
23 | /**
24 | * 是否启用虚拟Host
25 | */
26 | private boolean virtualHostEnabled = false;
27 | /**
28 | * 读超时时间
29 | */
30 | private int readTimeout = 100;
31 | /**
32 | * 写超时时间
33 | */
34 | private int writeTimeout = 100;
35 | /**
36 | * 连接超时时间
37 | */
38 | private int connectionTimeout = 60;
39 |
40 | public EnvContext.HttpConfig toClientConfig() {
41 | EnvContext.HttpConfig httpConfig = new EnvContext.HttpConfig();
42 | httpConfig.setConnectionTimeout(connectionTimeout);
43 | httpConfig.setReadTimeout(readTimeout);
44 | httpConfig.setWriteTimeout(writeTimeout);
45 | return httpConfig;
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/src/test/java/io/github/artislong/core/jdbc/JdbcOssClientTest.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.jdbc;
2 |
3 | import io.github.artislong.core.StandardOssClient;
4 | import io.github.artislong.core.StandardOssClientTest;
5 | import lombok.Getter;
6 | import org.junit.jupiter.api.Test;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.beans.factory.annotation.Qualifier;
9 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
10 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
11 | import org.springframework.boot.test.context.SpringBootTest;
12 |
13 | /**
14 | * @author 陈敏
15 | * @version JdbcOssClientTest.java, v 1.0 2022/3/14 0:04 chenmin Exp $
16 | * Created on 2022/3/14
17 | */
18 | @SpringBootTest
19 | @EnableAutoConfiguration(exclude = DataSourceAutoConfiguration.class) // 项目本身不使用数据库时,需增加此注解,移除数据源默认配置,仅需配置对象存储数据源即可
20 | public class JdbcOssClientTest implements StandardOssClientTest {
21 |
22 | @Getter
23 | @Autowired
24 | @Qualifier(JdbcOssConfiguration.DEFAULT_BEAN_NAME)
25 | private StandardOssClient ossClient;
26 |
27 | @Test
28 | public void test() throws Exception {
29 | upLoad();
30 | downLoad();
31 | copy();
32 | rename();
33 | move();
34 | isExist();
35 | getInfo();
36 | delete();
37 | }
38 |
39 | }
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/jinshan/model/JinShanOssConfig.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.jinshan.model;
2 |
3 | import com.ksyun.ks3.http.Region;
4 | import io.github.artislong.model.SliceConfig;
5 | import io.github.artislong.utils.OssPathUtil;
6 | import lombok.Data;
7 |
8 | /**
9 | * @author 陈敏
10 | * @version JinShanOssConfig.java, v 1.1 2022/3/3 22:28 chenmin Exp $
11 | * Created on 2022/3/3
12 | */
13 | @Data
14 | public class JinShanOssConfig {
15 | private String accessKeyId;
16 | private String accessKeySecret;
17 | private String bucketName;
18 | private String endpoint;
19 | /**
20 | * 服务地址,参考{@linkplain http://ks3.ksyun.com/doc/api/index.html Doc}
21 | * 中国(杭州):kss.ksyun.com
22 | * 中国(杭州)cdn:kssws.ks-cdn.com
23 | * 美国(圣克拉拉):ks3-us-west-1.ksyun.com
24 | * 中国(北京):ks3-cn-beijing.ksyun.com
25 | * 中国(香港):ks3-cn-hk-1.ksyun.com
26 | * 中国(上海):ks3-cn-shanghai.ksyun.com
27 | */
28 | private Region region = null;
29 | private String securityToken;
30 | private String basePath;
31 |
32 | private JinShanOssClientConfig clientConfig;
33 |
34 | /**
35 | * 断点续传参数
36 | */
37 | private SliceConfig sliceConfig = new SliceConfig();
38 |
39 | public void init() {
40 | this.sliceConfig.init();
41 | basePath = OssPathUtil.valid(basePath);
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/src/test/java/io/github/artislong/core/ali/AliOssClientTest.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.ali;
2 |
3 | import io.github.artislong.core.StandardOssClient;
4 | import io.github.artislong.core.StandardOssClientTest;
5 | import lombok.Getter;
6 | import org.junit.jupiter.api.Test;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.beans.factory.annotation.Qualifier;
9 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
10 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
11 | import org.springframework.boot.test.context.SpringBootTest;
12 |
13 | /**
14 | * @author 陈敏
15 | * @version AliOssClientTest.java, v 1.1 2021/11/16 21:19 chenmin Exp $
16 | * Created on 2021/11/16
17 | */
18 | @SpringBootTest
19 | @EnableAutoConfiguration(exclude = DataSourceAutoConfiguration.class)
20 | class AliOssClientTest implements StandardOssClientTest {
21 |
22 | @Getter
23 | @Autowired
24 | @Qualifier(AliOssConfiguration.DEFAULT_BEAN_NAME)
25 | private StandardOssClient ossClient;
26 |
27 | @Test
28 | public void test() throws Exception {
29 | upLoad();
30 | downLoad();
31 | copy();
32 | rename();
33 | move();
34 | isExist();
35 | getInfo();
36 | delete();
37 |
38 | upLoadCheckPoint();
39 | downloadCheckPoint();
40 | }
41 |
42 | }
--------------------------------------------------------------------------------
/src/test/java/io/github/artislong/core/up/UpOssClientTest.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.up;
2 |
3 | import io.github.artislong.core.StandardOssClient;
4 | import io.github.artislong.core.StandardOssClientTest;
5 | import lombok.Getter;
6 | import org.junit.jupiter.api.Test;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.beans.factory.annotation.Qualifier;
9 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
10 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
11 | import org.springframework.boot.test.context.SpringBootTest;
12 |
13 | /**
14 | * @author 陈敏
15 | * @version UpOssClientTest.java, v 1.1 2021/12/3 20:31 chenmin Exp $
16 | * Created on 2021/12/3
17 | */
18 | @SpringBootTest
19 | @EnableAutoConfiguration(exclude = DataSourceAutoConfiguration.class)
20 | public class UpOssClientTest implements StandardOssClientTest {
21 |
22 | @Getter
23 | @Autowired
24 | @Qualifier(UpOssConfiguration.DEFAULT_BEAN_NAME)
25 | private StandardOssClient ossClient;
26 |
27 | @Test
28 | public void test() throws Exception {
29 | upLoad();
30 | downLoad();
31 | copy();
32 | rename();
33 | move();
34 | isExist();
35 | getInfo();
36 | delete();
37 |
38 | upLoadCheckPoint();
39 | downloadCheckPoint();
40 | }
41 |
42 | }
--------------------------------------------------------------------------------
/src/test/java/io/github/artislong/core/sftp/SftpOssClientTest.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.sftp;
2 |
3 | import io.github.artislong.core.StandardOssClient;
4 | import io.github.artislong.core.StandardOssClientTest;
5 | import lombok.Getter;
6 | import org.junit.jupiter.api.Test;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.beans.factory.annotation.Qualifier;
9 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
10 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
11 | import org.springframework.boot.test.context.SpringBootTest;
12 |
13 | /**
14 | * @author 陈敏
15 | * @version SftpOssClientTest.java, v 1.1 2021/11/23 4:53 chenmin Exp $
16 | * Created on 2021/11/23
17 | */
18 | @SpringBootTest
19 | @EnableAutoConfiguration(exclude = DataSourceAutoConfiguration.class)
20 | public class SftpOssClientTest implements StandardOssClientTest {
21 |
22 | @Getter
23 | @Autowired
24 | @Qualifier(SftpOssConfiguration.DEFAULT_BEAN_NAME)
25 | private StandardOssClient ossClient;
26 |
27 | @Test
28 | public void test() throws Exception {
29 | upLoad();
30 | downLoad();
31 | copy();
32 | rename();
33 | move();
34 | isExist();
35 | getInfo();
36 | delete();
37 |
38 | upLoadCheckPoint();
39 | downloadCheckPoint();
40 | }
41 |
42 | }
--------------------------------------------------------------------------------
/src/test/java/io/github/artislong/core/jd/JdOssClientTest.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.jd;
2 |
3 | import io.github.artislong.core.StandardOssClient;
4 | import io.github.artislong.core.StandardOssClientTest;
5 | import lombok.Getter;
6 | import org.junit.jupiter.api.Test;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.beans.factory.annotation.Qualifier;
9 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
10 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
11 | import org.springframework.boot.test.context.SpringBootTest;
12 |
13 | /**
14 | * @author 陈敏
15 | * @version JdOssClientTest.java, v 1.1 2022/1/1 16:24 chenmin Exp $
16 | * Created on 2022/1/1
17 | */
18 | @SpringBootTest
19 | @EnableAutoConfiguration(exclude = DataSourceAutoConfiguration.class)
20 | public class JdOssClientTest implements StandardOssClientTest {
21 |
22 | @Getter
23 | @Autowired
24 | @Qualifier(JdOssConfiguration.DEFAULT_BEAN_NAME)
25 | private StandardOssClient ossClient;
26 |
27 | @Test
28 | public void test() throws Exception {
29 | // upLoad();
30 | // downLoad();
31 | // copy();
32 | // rename();
33 | // move();
34 | // isExist();
35 | getInfo();
36 | // delete();
37 | //
38 | // upLoadCheckPoint();
39 | // downloadCheckPoint();
40 | }
41 |
42 | }
--------------------------------------------------------------------------------
/src/test/java/io/github/artislong/core/baidu/BaiduOssClientTest.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.baidu;
2 |
3 | import io.github.artislong.core.StandardOssClient;
4 | import io.github.artislong.core.StandardOssClientTest;
5 | import lombok.Getter;
6 | import org.junit.jupiter.api.Test;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.beans.factory.annotation.Qualifier;
9 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
10 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
11 | import org.springframework.boot.test.context.SpringBootTest;
12 |
13 | /**
14 | * @author 陈敏
15 | * @version BaiduOssClientTest.java, v 1.1 2021/11/25 10:11 chenmin Exp $
16 | * Created on 2021/11/25
17 | */
18 | @SpringBootTest
19 | @EnableAutoConfiguration(exclude = DataSourceAutoConfiguration.class)
20 | public class BaiduOssClientTest implements StandardOssClientTest {
21 |
22 | @Getter
23 | @Autowired
24 | @Qualifier(BaiduOssConfiguration.DEFAULT_BEAN_NAME)
25 | private StandardOssClient ossClient;
26 |
27 | @Test
28 | public void test() throws Exception {
29 | upLoad();
30 | downLoad();
31 | copy();
32 | rename();
33 | move();
34 | isExist();
35 | getInfo();
36 | delete();
37 |
38 | upLoadCheckPoint();
39 | downloadCheckPoint();
40 | }
41 |
42 | }
--------------------------------------------------------------------------------
/src/test/java/io/github/artislong/core/local/LocalOssClientTest.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.local;
2 |
3 | import io.github.artislong.core.StandardOssClient;
4 | import io.github.artislong.core.StandardOssClientTest;
5 | import lombok.Getter;
6 | import org.junit.jupiter.api.Test;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.beans.factory.annotation.Qualifier;
9 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
10 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
11 | import org.springframework.boot.test.context.SpringBootTest;
12 |
13 | /**
14 | * @author 陈敏
15 | * @version LocalOssClientTest.java, v 1.1 2021/11/15 15:23 chenmin Exp $
16 | * Created on 2021/11/15
17 | */
18 | @SpringBootTest
19 | @EnableAutoConfiguration(exclude = DataSourceAutoConfiguration.class)
20 | public class LocalOssClientTest implements StandardOssClientTest {
21 |
22 | @Getter
23 | @Autowired
24 | @Qualifier(LocalOssConfiguration.DEFAULT_BEAN_NAME)
25 | private StandardOssClient ossClient;
26 |
27 | @Test
28 | public void test() throws Exception {
29 | upLoad();
30 | downLoad();
31 | copy();
32 | rename();
33 | move();
34 | isExist();
35 | getInfo();
36 | delete();
37 |
38 | upLoadCheckPoint();
39 | downloadCheckPoint();
40 | }
41 |
42 | }
--------------------------------------------------------------------------------
/src/test/java/io/github/artislong/core/minio/MinioOssClientTest.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.minio;
2 |
3 | import io.github.artislong.core.StandardOssClient;
4 | import io.github.artislong.core.StandardOssClientTest;
5 | import lombok.Getter;
6 | import org.junit.jupiter.api.Test;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.beans.factory.annotation.Qualifier;
9 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
10 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
11 | import org.springframework.boot.test.context.SpringBootTest;
12 |
13 | /**
14 | * @author 陈敏
15 | * @version MinioOssClientTest.java, v 1.1 2021/11/25 10:15 chenmin Exp $
16 | * Created on 2021/11/25
17 | */
18 | @SpringBootTest
19 | @EnableAutoConfiguration(exclude = DataSourceAutoConfiguration.class)
20 | public class MinioOssClientTest implements StandardOssClientTest {
21 |
22 | @Getter
23 | @Autowired
24 | @Qualifier(MinioOssConfiguration.DEFAULT_BEAN_NAME)
25 | private StandardOssClient ossClient;
26 |
27 | @Test
28 | public void test() throws Exception {
29 | upLoad();
30 | downLoad();
31 | copy();
32 | rename();
33 | move();
34 | isExist();
35 | getInfo();
36 | delete();
37 |
38 | upLoadCheckPoint();
39 | downloadCheckPoint();
40 | }
41 |
42 | }
--------------------------------------------------------------------------------
/src/test/java/io/github/artislong/core/qiniu/QiNiuOssClientTest.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.qiniu;
2 |
3 | import io.github.artislong.core.StandardOssClient;
4 | import io.github.artislong.core.StandardOssClientTest;
5 | import lombok.Getter;
6 | import org.junit.jupiter.api.Test;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.beans.factory.annotation.Qualifier;
9 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
10 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
11 | import org.springframework.boot.test.context.SpringBootTest;
12 |
13 | /**
14 | * @author 陈敏
15 | * @version QiNiuOssClientTest.java, v 1.1 2021/11/25 10:17 chenmin Exp $
16 | * Created on 2021/11/25
17 | */
18 | @SpringBootTest
19 | @EnableAutoConfiguration(exclude = DataSourceAutoConfiguration.class)
20 | public class QiNiuOssClientTest implements StandardOssClientTest {
21 |
22 | @Getter
23 | @Autowired
24 | @Qualifier(QiNiuOssConfiguration.DEFAULT_BEAN_NAME)
25 | private StandardOssClient ossClient;
26 |
27 | @Test
28 | public void test() throws Exception {
29 | upLoad();
30 | downLoad();
31 | copy();
32 | rename();
33 | move();
34 | isExist();
35 | getInfo();
36 | delete();
37 |
38 | upLoadCheckPoint();
39 | downloadCheckPoint();
40 | }
41 |
42 | }
--------------------------------------------------------------------------------
/src/test/java/io/github/artislong/core/huawei/HuaWeiOssClientTest.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.huawei;
2 |
3 | import io.github.artislong.core.StandardOssClient;
4 | import io.github.artislong.core.StandardOssClientTest;
5 | import lombok.Getter;
6 | import org.junit.jupiter.api.Test;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.beans.factory.annotation.Qualifier;
9 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
10 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
11 | import org.springframework.boot.test.context.SpringBootTest;
12 |
13 | /**
14 | * @author 陈敏
15 | * @version HuaWeiOssClientTest.java, v 1.1 2021/11/25 10:15 chenmin Exp $
16 | * Created on 2021/11/25
17 | */
18 | @SpringBootTest
19 | @EnableAutoConfiguration(exclude = DataSourceAutoConfiguration.class)
20 | public class HuaWeiOssClientTest implements StandardOssClientTest {
21 |
22 | @Getter
23 | @Autowired
24 | @Qualifier(HuaWeiOssConfiguration.DEFAULT_BEAN_NAME)
25 | private StandardOssClient ossClient;
26 |
27 | @Test
28 | public void test() throws Exception {
29 | upLoad();
30 | downLoad();
31 | copy();
32 | rename();
33 | move();
34 | isExist();
35 | getInfo();
36 | delete();
37 |
38 | upLoadCheckPoint();
39 | downloadCheckPoint();
40 | }
41 |
42 | }
--------------------------------------------------------------------------------
/src/test/java/io/github/artislong/core/jinshan/JinShanOssClientTest.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.jinshan;
2 |
3 | import io.github.artislong.core.StandardOssClient;
4 | import io.github.artislong.core.StandardOssClientTest;
5 | import lombok.Getter;
6 | import org.junit.jupiter.api.Test;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.beans.factory.annotation.Qualifier;
9 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
10 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
11 | import org.springframework.boot.test.context.SpringBootTest;
12 |
13 | /**
14 | * @author 陈敏
15 | * @version JinShanOssClientTest.java, v 1.1 2022/3/3 23:09 chenmin Exp $
16 | * Created on 2022/3/3
17 | */
18 | @SpringBootTest
19 | @EnableAutoConfiguration(exclude = DataSourceAutoConfiguration.class)
20 | public class JinShanOssClientTest implements StandardOssClientTest {
21 |
22 | @Getter
23 | @Autowired
24 | @Qualifier(JinShanOssConfiguration.DEFAULT_BEAN_NAME)
25 | private StandardOssClient ossClient;
26 |
27 | @Test
28 | public void test() throws Exception {
29 | upLoad();
30 | downLoad();
31 | copy();
32 | rename();
33 | move();
34 | isExist();
35 | getInfo();
36 | delete();
37 |
38 | upLoadCheckPoint();
39 | downloadCheckPoint();
40 | }
41 |
42 | }
--------------------------------------------------------------------------------
/src/test/java/io/github/artislong/core/qingyun/QingYunOssClientTest.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.qingyun;
2 |
3 | import io.github.artislong.core.StandardOssClient;
4 | import io.github.artislong.core.StandardOssClientTest;
5 | import lombok.Getter;
6 | import org.junit.jupiter.api.Test;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.beans.factory.annotation.Qualifier;
9 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
10 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
11 | import org.springframework.boot.test.context.SpringBootTest;
12 |
13 | /**
14 | * @author 陈敏
15 | * @version QingYunOssClientTest.java, v 1.0 2022/3/17 22:54 chenmin Exp $
16 | * Created on 2022/3/17
17 | */
18 | @SpringBootTest
19 | @EnableAutoConfiguration(exclude = DataSourceAutoConfiguration.class)
20 | public class QingYunOssClientTest implements StandardOssClientTest {
21 |
22 | @Getter
23 | @Autowired
24 | @Qualifier(QingYunOssConfiguration.DEFAULT_BEAN_NAME)
25 | private StandardOssClient ossClient;
26 |
27 | @Test
28 | public void test() throws Exception {
29 | upLoad();
30 | downLoad();
31 | copy();
32 | rename();
33 | move();
34 | isExist();
35 | getInfo();
36 | delete();
37 |
38 | upLoadCheckPoint();
39 | downloadCheckPoint();
40 | }
41 | }
--------------------------------------------------------------------------------
/src/test/java/io/github/artislong/core/tencent/TencentOssClientTest.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.tencent;
2 |
3 | import io.github.artislong.core.StandardOssClient;
4 | import io.github.artislong.core.StandardOssClientTest;
5 | import lombok.Getter;
6 | import org.junit.jupiter.api.Test;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.beans.factory.annotation.Qualifier;
9 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
10 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
11 | import org.springframework.boot.test.context.SpringBootTest;
12 |
13 | /**
14 | * @author 陈敏
15 | * @version TencentOssClientTest.java, v 1.1 2021/11/25 10:18 chenmin Exp $
16 | * Created on 2021/11/25
17 | */
18 | @SpringBootTest
19 | @EnableAutoConfiguration(exclude = DataSourceAutoConfiguration.class)
20 | public class TencentOssClientTest implements StandardOssClientTest {
21 |
22 | @Getter
23 | @Autowired
24 | @Qualifier(TencentOssConfiguration.DEFAULT_BEAN_NAME)
25 | private StandardOssClient ossClient;
26 |
27 | @Test
28 | public void test() throws Exception {
29 | upLoad();
30 | downLoad();
31 | copy();
32 | rename();
33 | move();
34 | isExist();
35 | getInfo();
36 | delete();
37 |
38 | upLoadCheckPoint();
39 | downloadCheckPoint();
40 | }
41 |
42 | }
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/model/upload/UpLoadFileStat.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.model.upload;
2 |
3 | import lombok.Data;
4 |
5 | import java.io.File;
6 | import java.io.Serializable;
7 |
8 | /**
9 | * 文件状态
10 | * @author 陈敏
11 | * @version FileStat.java, v 1.1 2022/2/9 22:54 chenmin Exp $
12 | * Created on 2022/2/9
13 | */
14 | @Data
15 | public class UpLoadFileStat implements Serializable {
16 |
17 | private static final long serialVersionUID = -1223810339796425415L;
18 |
19 | /**
20 | * 文件大小
21 | */
22 | private long size;
23 | /**
24 | * 文件最新修改时间
25 | */
26 | private long lastModified;
27 | /**
28 | * 文件内容签名
29 | */
30 | private String digest;
31 |
32 | @Override
33 | public int hashCode() {
34 | final int prime = 31;
35 | int result = 1;
36 | result = prime * result + ((digest == null) ? 0 : digest.hashCode());
37 | result = prime * result + (int) (lastModified ^ (lastModified >>> 32));
38 | result = prime * result + (int) (size ^ (size >>> 32));
39 | return result;
40 | }
41 |
42 | public static UpLoadFileStat getFileStat(String uploadFile) {
43 | UpLoadFileStat fileStat = new UpLoadFileStat();
44 | File file = new File(uploadFile);
45 | fileStat.setSize(file.length());
46 | fileStat.setLastModified(file.lastModified());
47 | return fileStat;
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/tencent/constant/TencentOssConstant.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.tencent.constant;
2 |
3 | import com.qcloud.cos.utils.VersionInfoUtils;
4 |
5 | /**
6 | * @author 陈敏
7 | * @version TencentOssConstant.java, v 1.0 2022/4/19 20:06 chenmin Exp $
8 | * Created on 2022/4/19
9 | */
10 | public class TencentOssConstant {
11 | /**
12 | * 默认的获取连接的超时时间, 单位ms
13 | */
14 | public static final int DEFAULT_CONNECTION_REQUEST_TIMEOUT = -1;
15 | /**
16 | * 默认连接超时, 单位ms
17 | */
18 | public static final int DEFAULT_CONNECTION_TIMEOUT = 30 * 1000;
19 | /**
20 | * 默认的SOCKET读取超时时间, 单位ms
21 | */
22 | public static final int DEFAULT_SOCKET_TIMEOUT = 30 * 1000;
23 | /**
24 | * 默认的维护最大HTTP连接数
25 | */
26 | public static final int DEFAULT_MAX_CONNECTIONS_COUNT = 1024;
27 | /**
28 | * 空闲连接最长存活时间
29 | */
30 | public static final int DEFAULT_IDLE_CONNECTION_ALIVE = 60 * 1000;
31 | /**
32 | * 多次签名的默认过期时间,单位秒
33 | */
34 | public static final long DEFAULT_SIGN_EXPIRED = 3600;
35 | /**
36 | * 默认的user_agent标识
37 | */
38 | public static final String DEFAULT_USER_AGENT = VersionInfoUtils.getUserAgent();
39 | /**
40 | * Read Limit
41 | */
42 | public static final int DEFAULT_READ_LIMIT = (2 << 17) + 1;
43 | /**
44 | * 发生异常时的最大重试次数
45 | */
46 | public static final int DEFAULT_RETRY_TIMES = 3;
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/resources/jdbc/schema-oracle.sql:
--------------------------------------------------------------------------------
1 | -- DROP TABLE OSS_STORE;
2 | -- DROP TABLE OSS_DATA;
3 |
4 | CREATE TABLE OSS_STORE
5 | (
6 | ID VARCHAR2(50) PRIMARY KEY,
7 | NAME VARCHAR2(100) NOT NULL,
8 | PATH VARCHAR2(500) NOT NULL,
9 | LENGTH NUMBER,
10 | CREATE_TIME DATE,
11 | LAST_UPDATE_TIME DATE,
12 | PARENT_ID VARCHAR2(50) DEFAULT 0,
13 | TYPE VARCHAR2(2) NOT NULL,
14 | DATA_ID VARCHAR2(50)
15 | );
16 |
17 | COMMENT ON TABLE OSS_STORE IS '对象存储';
18 | COMMENT ON COLUMN OSS_STORE.ID IS '主键';
19 | COMMENT ON COLUMN OSS_STORE.NAME IS '文件/目录名';
20 | COMMENT ON COLUMN OSS_STORE.PATH IS '路径';
21 | COMMENT ON COLUMN OSS_STORE.LENGTH IS '文件大小';
22 | COMMENT ON COLUMN OSS_STORE.CREATE_TIME IS '创建时间';
23 | COMMENT ON COLUMN OSS_STORE.LAST_UPDATE_TIME IS '最新修改时间';
24 | COMMENT ON COLUMN OSS_STORE.PARENT_ID IS '父级目录ID';
25 | COMMENT ON COLUMN OSS_STORE.TYPE IS '类型(D:目录;F:文件)';
26 | COMMENT ON COLUMN OSS_STORE.DATA_ID IS '数据ID';
27 |
28 | CREATE INDEX OSS_STORE_NAME_INDEX ON OSS_STORE (NAME);
29 | CREATE INDEX OSS_STORE_PATH_INDEX ON OSS_STORE (PATH);
30 | CREATE INDEX OSS_STORE_PARENT_INDEX ON OSS_STORE (PARENT_ID);
31 |
32 | CREATE TABLE OSS_DATA
33 | (
34 | ID VARCHAR2(50) PRIMARY KEY,
35 | DATA BLOB
36 | );
37 |
38 | COMMENT ON TABLE OSS_DATA IS '数据';
39 | COMMENT ON COLUMN OSS_DATA.ID IS '主键';
40 | COMMENT ON COLUMN OSS_DATA.DATA IS '数据';
41 |
42 |
43 |
--------------------------------------------------------------------------------
/docs/local/README.md:
--------------------------------------------------------------------------------
1 | ## 开始使用
2 |
3 | 引入以下依赖
4 |
5 | ```xml
6 |
7 | io.github.artislong
8 | oss-spring-boot-starter
9 | {latest.version}
10 |
11 | ```
12 |
13 | 通过`oss.local.enable=true`开启本地存储自动配置
14 |
15 | ## 配置详解
16 |
17 | **注:**所有具有默认值的属性,配置都可缺省,且不支持复用。
18 |
19 | - 单个本地存储配置
20 |
21 | ```yaml
22 | oss:
23 | local:
24 | enable: true
25 | base-path: 本地对象存储路径
26 | slice-config:
27 | task-num: 8
28 | part-size: 104857600
29 | ```
30 |
31 | 通过如上配置即可开启本地存储,可通过以下方式注入标准的OSS客户端。
32 |
33 | ```java
34 | @Autowired
35 | @Qualifier(LocalOssConfiguration.DEFAULT_BEAN_NAME)
36 | private StandardOssClient ossClient;
37 | ```
38 |
39 | - 多个本地存储配置
40 |
41 | ```yaml
42 | oss:
43 | local:
44 | enable: true
45 | oss-config:
46 | localOssClient1:
47 | base-path: F:/data/
48 | slice-config:
49 | task-num: 8 # 并发线程数,默认等于CPU的核数
50 | part-size: 104857600 # 分片大小,单位KB,默认5MB
51 | localOssClient2:
52 | base-path: E:/data/
53 | slice-config:
54 | task-num: 8 # 并发线程数,默认等于CPU的核数
55 | part-size: 104857600 # 分片大小,单位KB,默认5MB
56 | ```
57 |
58 | 当配置多个本地对象存储时,使用如下方式注入
59 |
60 | ```java
61 | @Autowired
62 | @Qualifier("localOssClient1")
63 | private StandardOssClient localOssClient1;
64 | @Autowired
65 | @Qualifier("localOssClient2")
66 | private StandardOssClient localOssClient2;
67 | ```
68 |
69 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/sftp/model/SftpOssConfig.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.sftp.model;
2 |
3 | import cn.hutool.core.bean.BeanUtil;
4 | import cn.hutool.core.bean.copier.CopyOptions;
5 | import cn.hutool.extra.ftp.FtpConfig;
6 | import io.github.artislong.utils.OssPathUtil;
7 | import lombok.Data;
8 |
9 | import java.nio.charset.Charset;
10 |
11 | /**
12 | * @author 陈敏
13 | * @version SftpOssConfig.java, v 1.1 2022/2/20 9:06 chenmin Exp $
14 | * Created on 2022/2/20
15 | */
16 | @Data
17 | public class SftpOssConfig {
18 |
19 | private String basePath;
20 |
21 | /**
22 | * 主机
23 | */
24 | private String host;
25 | /**
26 | * 端口
27 | */
28 | private int port;
29 | /**
30 | * 用户名
31 | */
32 | private String user;
33 | /**
34 | * 密码
35 | */
36 | private String password;
37 | /**
38 | * 编码
39 | */
40 | private Charset charset;
41 |
42 | private SftpOssClientConfig clientConfig;
43 |
44 | public void init() {
45 | basePath = OssPathUtil.valid(basePath);
46 | }
47 |
48 | public FtpConfig toFtpConfig() {
49 | FtpConfig ftpConfig = new FtpConfig();
50 | BeanUtil.copyProperties(this, ftpConfig,
51 | new CopyOptions().setIgnoreNullValue(true).setIgnoreProperties("basePath", "clientConfig"));
52 | BeanUtil.copyProperties(this.getClientConfig(), ftpConfig, new CopyOptions().setIgnoreNullValue(true));
53 | return ftpConfig;
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/ucloud/model/UCloudOssClientConfig.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.ucloud.model;
2 |
3 | import cn.hutool.core.bean.BeanUtil;
4 | import cn.ucloud.ufile.http.HttpClient;
5 | import lombok.Data;
6 | import lombok.experimental.Accessors;
7 |
8 | import java.util.concurrent.TimeUnit;
9 |
10 | import static cn.ucloud.ufile.http.HttpClient.Config.*;
11 |
12 | /**
13 | * @author 陈敏
14 | * @version UCloudOssClientConfig.java, v 1.0 2022/4/21 10:01 chenmin Exp $
15 | * Created on 2022/4/21
16 | */
17 | @Data
18 | @Accessors(chain = true)
19 | public class UCloudOssClientConfig {
20 | /**
21 | * 连接超时时间
22 | */
23 | private long timeoutConnect = DEFAULT_CONNECT_TIMEOUT;
24 | /**
25 | * 读超时时间
26 | */
27 | private long timeoutRead = DEFAULT_WRITE_TIMEOUT;
28 | /**
29 | * 写超时时间
30 | */
31 | private long timeoutWrite = DEFAULT_READ_TIMEOUT;
32 | /**
33 | * okhttp最大空闲连接数(5)
34 | */
35 | private int maxIdleConnections = DEFAULT_MAX_IDLE_CONNECTIONS;
36 | /**
37 | * okhttp活动链接存货时间(5分钟)
38 | */
39 | private long keepAliveDuration = DEFAULT_KEEP_ALIVE_DURATION_MINUTES;
40 | /**
41 | * okhttp活动链接存货时间单位, (分钟)
42 | */
43 | private TimeUnit keepAliveTimeUnit = DEFAULT_KEEP_ALIVE_DURATION_TIME_UNIT;
44 |
45 | public HttpClient.Config toClientConfig() {
46 | HttpClient.Config config = new HttpClient.Config();
47 | BeanUtil.copyProperties(this, config);
48 | return config;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/ftp/model/FtpOssConfig.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.ftp.model;
2 |
3 | import cn.hutool.core.bean.BeanUtil;
4 | import cn.hutool.core.bean.copier.CopyOptions;
5 | import cn.hutool.extra.ftp.FtpConfig;
6 | import io.github.artislong.utils.OssPathUtil;
7 | import lombok.Data;
8 | import lombok.extern.slf4j.Slf4j;
9 |
10 | import java.nio.charset.Charset;
11 |
12 | /**
13 | * @author 陈敏
14 | * @version FtpOssConfig.java, v 1.1 2022/2/19 18:29 chenmin Exp $
15 | * Created on 2022/2/19
16 | */
17 | @Slf4j
18 | @Data
19 | public class FtpOssConfig {
20 |
21 | private String basePath;
22 |
23 | /**
24 | * 主机
25 | */
26 | private String host;
27 | /**
28 | * 端口
29 | */
30 | private int port;
31 | /**
32 | * 用户名
33 | */
34 | private String user;
35 | /**
36 | * 密码
37 | */
38 | private String password;
39 | /**
40 | * 编码
41 | */
42 | private Charset charset;
43 |
44 | private FtpOssClientConfig clientConfig;
45 |
46 | public void init() {
47 | basePath = OssPathUtil.valid(basePath);
48 | }
49 |
50 | public FtpConfig toFtpConfig() {
51 | FtpConfig ftpConfig = new FtpConfig();
52 | BeanUtil.copyProperties(this, ftpConfig,
53 | new CopyOptions().setIgnoreNullValue(true).setIgnoreProperties("basePath", "clientConfig"));
54 | BeanUtil.copyProperties(this.getClientConfig(), ftpConfig,
55 | new CopyOptions().setIgnoreNullValue(true).setIgnoreProperties("mode", "backToPwd"));
56 | return ftpConfig;
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/constant/OssConstant.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.constant;
2 |
3 | import java.util.concurrent.TimeUnit;
4 |
5 | /**
6 | * @author 陈敏
7 | * @version OssConstant.java, v 1.1 2021/11/5 11:06 chenmin Exp $
8 | * Created on 2021/11/5
9 | */
10 | public class OssConstant {
11 |
12 | public static final String OSS = "oss";
13 | public static final String ENABLE = "enable";
14 | public static final String DEFAULT_ENABLE_VALUE = "true";
15 |
16 | public static final int KB = 1024;
17 |
18 | public static final int MB = 1024 * KB;
19 | /**
20 | * 默认分片大小
21 | */
22 | public static final Long DEFAULT_PART_SIZE = 5L * MB;
23 | /**
24 | * 默认缓冲区大小
25 | */
26 | public static final int DEFAULT_BUFFER_SIZE = 8 * KB;
27 | /**
28 | * 默认最大分片数
29 | */
30 | public static final Long DEFAULT_PART_NUM = 10000L;
31 | /**
32 | * 默认并发线程数
33 | */
34 | public static final Integer DEFAULT_TASK_NUM = Runtime.getRuntime().availableProcessors();
35 |
36 | public static final Long DEFAULT_CONNECTION_TIMEOUT = TimeUnit.MINUTES.toMillis(5);
37 |
38 | /**
39 | * OSS存储类型
40 | */
41 | public interface OssType {
42 | String LOCAL = "local";
43 | String FTP = "ftp";
44 | String SFTP = "sftp";
45 | String ALI = "ali";
46 | String QINIU = "qiniu";
47 | String MINIO = "minio";
48 | String BAIDU = "baidu";
49 | String TENCENT = "tencent";
50 | String HUAWEI = "huawei";
51 | String JD = "jd";
52 | String UP = "up";
53 | String JINSHAN = "jinshan";
54 | String WANGYI = "wangyi";
55 | String UCLOUD = "ucloud";
56 | String PINGAN = "pingan";
57 | String QINGYUN = "qingyun";
58 | String JDBC = "jdbc";
59 | String AWS = "aws";
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/jinshan/model/JinShanOssClientConfig.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.jinshan.model;
2 |
3 | import cn.hutool.core.bean.BeanUtil;
4 | import com.ksyun.ks3.http.HttpClientConfig;
5 | import lombok.Data;
6 | import lombok.EqualsAndHashCode;
7 |
8 | /**
9 | * @author 陈敏
10 | * @version JinShanOssClientConfig.java, v 1.0 2022/5/2 19:18 chenmin Exp $
11 | * Created on 2022/5/2
12 | */
13 | @Data
14 | @EqualsAndHashCode(callSuper = true)
15 | public class JinShanOssClientConfig extends HttpClientConfig {
16 | /**
17 | * http或者https
18 | */
19 | private Ks3ClientConfig.PROTOCOL protocol = Ks3ClientConfig.PROTOCOL.http;
20 | /**
21 | * 签名版本
22 | */
23 | private Ks3ClientConfig.SignerVersion version = Ks3ClientConfig.SignerVersion.V2;
24 | /**
25 | * 是否使用path style access方式访问
26 | */
27 | private boolean pathStyleAccess = false;
28 | /**
29 | * 允许客户端发送匿名请求
30 | */
31 | private boolean allowAnonymous = true;
32 | /**
33 | * 当服务端返回307时是否自动跳转,
34 | * 主要发生在用Region A的endpoint请求Region B的endpoint
35 | */
36 | private boolean flowRedirect = true;
37 | /**
38 | * 是否使用绑定的域名作为endpoint
39 | */
40 | private boolean domainMode = false;
41 | /**
42 | * 签名类
43 | */
44 | private String signerClass = "com.ksyun.ks3.signer.DefaultSigner";
45 | private boolean useGzip = false;
46 |
47 | public Ks3ClientConfig toClientConfig() {
48 | Ks3ClientConfig clientConfig = new Ks3ClientConfig();
49 | BeanUtil.copyProperties(this, clientConfig);
50 | return clientConfig;
51 | }
52 |
53 | public HttpClientConfig toHttpClientConfig() {
54 | HttpClientConfig httpClientConfig = new HttpClientConfig();
55 | BeanUtil.copyProperties(this, httpClientConfig);
56 | return httpClientConfig;
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/src/test/java/io/github/artislong/core/StandardOssClientTest.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core;
2 |
3 | import cn.hutool.core.io.FileUtil;
4 | import cn.hutool.core.util.StrUtil;
5 | import io.github.artislong.model.OssInfo;
6 |
7 | /**
8 | * @author 陈敏
9 | * @version StandardOssClientTest.java, v 1.1 2022/3/1 11:32 chenmin Exp $
10 | * Created on 2022/3/1
11 | */
12 | public interface StandardOssClientTest {
13 |
14 | default void upLoad() {
15 | OssInfo ossInfo = getOssClient().upLoad(FileUtil.getInputStream("/Users/admin/test.png"), "test.png");
16 | System.out.println(ossInfo);
17 | }
18 |
19 | default void upLoadCheckPoint() {
20 | OssInfo ossInfo = getOssClient().upLoadCheckPoint("/Users/admin/test.zip", "test.zip");
21 | System.out.println(ossInfo);
22 | }
23 |
24 | default void downLoad() {
25 | getOssClient().downLoad(FileUtil.getOutputStream("/Users/admin/test.png"), "test1.png");
26 | }
27 |
28 | default void downloadCheckPoint() {
29 | getOssClient().downLoadCheckPoint("/Users/admin/test.zip", "test.zip");
30 | }
31 |
32 | default void delete() {
33 | getOssClient().delete("test1.png");
34 | }
35 |
36 | default void copy() {
37 | getOssClient().copy("test.png", "test1.png");
38 | }
39 |
40 | default void move() {
41 | getOssClient().move("test1.png", "test2.png");
42 | }
43 |
44 | default void rename() {
45 | getOssClient().rename("test2.png", "test1.png");
46 | }
47 |
48 | default void getInfo() {
49 | // OssInfo info = getOssClient().getInfo("test.png");
50 | // System.out.println(info);
51 | OssInfo info = getOssClient().getInfo(StrUtil.SLASH, true);
52 | System.out.println(info);
53 | }
54 |
55 | default void isExist() {
56 | System.out.println(getOssClient().isExist("test.png"));
57 | }
58 |
59 | StandardOssClient getOssClient();
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/aws/constant/AwsRegion.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.aws.constant;
2 |
3 | import software.amazon.awssdk.regions.Region;
4 |
5 | /**
6 | * @author 陈敏
7 | * @version Region.java, v 1.0 2022/4/1 23:05 chenmin Exp $
8 | * Created on 2022/4/1
9 | */
10 | public enum AwsRegion {
11 |
12 | AP_SOUTH_1(Region.AP_SOUTH_1),
13 | EU_SOUTH_1(Region.EU_SOUTH_1),
14 | US_GOV_EAST_1(Region.US_GOV_EAST_1),
15 | CA_CENTRAL_1(Region.CA_CENTRAL_1),
16 | EU_CENTRAL_1(Region.EU_CENTRAL_1),
17 | US_ISO_WEST_1(Region.US_ISO_WEST_1),
18 | US_WEST_1(Region.US_WEST_1),
19 | US_WEST_2(Region.US_WEST_2),
20 | AF_SOUTH_1(Region.AF_SOUTH_1),
21 | EU_NORTH_1(Region.EU_NORTH_1),
22 | EU_WEST_3(Region.EU_WEST_3),
23 | EU_WEST_2(Region.EU_WEST_2),
24 | EU_WEST_1(Region.EU_WEST_1),
25 | AP_NORTHEAST_3(Region.AP_NORTHEAST_3),
26 | AP_NORTHEAST_2(Region.AP_NORTHEAST_2),
27 | AP_NORTHEAST_1(Region.AP_NORTHEAST_1),
28 | ME_SOUTH_1(Region.ME_SOUTH_1),
29 | SA_EAST_1(Region.SA_EAST_1),
30 | AP_EAST_1(Region.AP_EAST_1),
31 | CN_NORTH_1(Region.CN_NORTH_1),
32 | US_GOV_WEST_1(Region.US_GOV_WEST_1),
33 | AP_SOUTHEAST_1(Region.AP_SOUTHEAST_1),
34 | AP_SOUTHEAST_2(Region.AP_SOUTHEAST_2),
35 | US_ISO_EAST_1(Region.US_ISO_EAST_1),
36 | AP_SOUTHEAST_3(Region.AP_SOUTHEAST_3),
37 | US_EAST_1(Region.US_EAST_1),
38 | US_EAST_2(Region.US_EAST_2),
39 | CN_NORTHWEST_1(Region.CN_NORTHWEST_1),
40 | US_ISOB_EAST_1(Region.US_ISOB_EAST_1),
41 | AWS_GLOBAL(Region.AWS_GLOBAL),
42 | AWS_CN_GLOBAL(Region.AWS_CN_GLOBAL),
43 | AWS_US_GOV_GLOBAL(Region.AWS_US_GOV_GLOBAL),
44 | AWS_ISO_GLOBAL(Region.AWS_ISO_GLOBAL),
45 | AWS_ISO_B_GLOBAL(Region.AWS_ISO_B_GLOBAL);
46 | private final Region region;
47 |
48 | AwsRegion(Region region) {
49 | this.region = region;
50 | }
51 |
52 | public Region getRegion() {
53 | return region;
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/model/upload/UpLoadPartEntityTag.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.model.upload;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Data;
5 | import lombok.NoArgsConstructor;
6 | import lombok.experimental.Accessors;
7 |
8 | import java.io.Serializable;
9 |
10 | /**
11 | * 分块标签
12 | * @author 陈敏
13 | * @version PartETag.java, v 1.1 2022/2/10 23:38 chenmin Exp $
14 | * Created on 2022/2/10
15 | */
16 | @Data
17 | @Accessors(chain = true)
18 | @AllArgsConstructor
19 | @NoArgsConstructor
20 | public class UpLoadPartEntityTag implements Serializable {
21 |
22 | private static final long serialVersionUID = 2471854027355307627L;
23 |
24 | /**
25 | * 分块号
26 | */
27 | private int partNumber;
28 |
29 | /**
30 | * 标签
31 | */
32 | private String eTag;
33 |
34 | @Override
35 | public int hashCode() {
36 | final int prime = 31;
37 | int result = 1;
38 | result = prime * result + ((this.eTag == null) ? 0 : this.eTag.hashCode());
39 | result = prime * result + this.partNumber;
40 | return result;
41 | }
42 |
43 | @Override
44 | public boolean equals(Object obj) {
45 | if (this == obj) {
46 | return true;
47 | }
48 | if (obj == null) {
49 | return false;
50 | }
51 | if (this.getClass() != obj.getClass()) {
52 | return false;
53 | }
54 | UpLoadPartEntityTag other = (UpLoadPartEntityTag) obj;
55 | if (this.eTag == null) {
56 | if (other.eTag != null) {
57 | return false;
58 | }
59 | } else if (!this.eTag.equals(other.eTag)) {
60 | return false;
61 | }
62 | if (this.partNumber != other.partNumber) {
63 | return false;
64 | }
65 | return true;
66 | }
67 |
68 | @Override
69 | public String toString() {
70 | return "PartETag [partNumber=" + this.partNumber + ", eTag=" + this.eTag + "]";
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/constant/OssType.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.constant;
2 |
3 | /**
4 | * @author 陈敏
5 | * @version OssType.java, v 1.1 2021/11/16 21:54 chenmin Exp $
6 | * Created on 2021/11/16
7 | */
8 | public enum OssType {
9 |
10 | /**
11 | * 本地磁盘存储
12 | */
13 | LOCAL(OssConstant.OssType.LOCAL),
14 |
15 | /**
16 | * FTP协议存储
17 | */
18 | FTP(OssConstant.OssType.FTP),
19 |
20 | /**
21 | * SFTP存储
22 | */
23 | SFTP(OssConstant.OssType.SFTP),
24 |
25 | /**
26 | * 阿里OSS存储
27 | */
28 | ALI(OssConstant.OssType.ALI),
29 |
30 | /**
31 | * 七牛云存储
32 | */
33 | QINIU(OssConstant.OssType.QINIU),
34 |
35 | /**
36 | * MinIO存储
37 | */
38 | MINIO(OssConstant.OssType.MINIO),
39 |
40 | /**
41 | * 百度云存储
42 | */
43 | BAIDU(OssConstant.OssType.BAIDU),
44 |
45 | /**
46 | * 腾讯云存储
47 | */
48 | TENCENT(OssConstant.OssType.TENCENT),
49 |
50 | /**
51 | * 华为云存储
52 | */
53 | HUAWEI(OssConstant.OssType.HUAWEI),
54 |
55 | /**
56 | * 京东云存储
57 | */
58 | JD(OssConstant.OssType.JD),
59 |
60 | /**
61 | * 又拍云存储
62 | */
63 | UP(OssConstant.OssType.UP),
64 |
65 | /**
66 | * 金山云
67 | */
68 | JINSHAN(OssConstant.OssType.JINSHAN),
69 |
70 | /**
71 | * 网易数帆
72 | */
73 | WANGYI(OssConstant.OssType.WANGYI),
74 |
75 | /**
76 | * UCloud
77 | */
78 | UCLOUD(OssConstant.OssType.UCLOUD),
79 |
80 | /**
81 | * 平安云
82 | */
83 | PINGAN(OssConstant.OssType.PINGAN),
84 |
85 | /**
86 | * 青云
87 | */
88 | QINGYUN(OssConstant.OssType.QINGYUN),
89 |
90 | /**
91 | * JDBC
92 | */
93 | JDBC(OssConstant.OssType.JDBC),
94 |
95 | /**
96 | * 亚马逊
97 | */
98 | AWS(OssConstant.OssType.AWS);
99 |
100 | private final String value;
101 |
102 | OssType(String value) {
103 | this.value = value;
104 | }
105 |
106 | public String getValue() {
107 | return value;
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/local/LocalOssConfiguration.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.local;
2 |
3 | import cn.hutool.core.text.CharPool;
4 | import cn.hutool.extra.spring.SpringUtil;
5 | import com.aliyun.oss.OSSClient;
6 | import io.github.artislong.constant.OssConstant;
7 | import io.github.artislong.core.StandardOssClient;
8 | import io.github.artislong.core.local.model.LocalOssConfig;
9 | import org.springframework.beans.factory.annotation.Autowired;
10 | import org.springframework.boot.SpringBootConfiguration;
11 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
12 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
13 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
14 | import org.springframework.context.annotation.Bean;
15 |
16 | import java.util.Map;
17 |
18 | /**
19 | * @author 陈敏
20 | * @version LocalConfiguration.java, v 1.1 2022/2/11 15:28 chenmin Exp $
21 | * Created on 2022/2/11
22 | */
23 | @SpringBootConfiguration
24 | @ConditionalOnClass(OSSClient.class)
25 | @EnableConfigurationProperties({LocalOssProperties.class})
26 | @ConditionalOnProperty(prefix = OssConstant.OSS, name = OssConstant.OssType.LOCAL + CharPool.DOT + OssConstant.ENABLE,
27 | havingValue = OssConstant.DEFAULT_ENABLE_VALUE, matchIfMissing = true)
28 | public class LocalOssConfiguration {
29 |
30 | public static final String DEFAULT_BEAN_NAME = "localOssClient";
31 |
32 | @Autowired
33 | private LocalOssProperties localProperties;
34 |
35 | @Bean
36 | public StandardOssClient localOssClient() {
37 | Map localOssConfigMap = localProperties.getOssConfig();
38 | if (localOssConfigMap.isEmpty()) {
39 | SpringUtil.registerBean(DEFAULT_BEAN_NAME, localOssClient(localProperties));
40 | } else {
41 | localOssConfigMap.forEach((name, localOssConfig) -> SpringUtil.registerBean(name, localOssClient(localOssConfig)));
42 | }
43 | return null;
44 | }
45 |
46 | public StandardOssClient localOssClient(LocalOssConfig localOssConfig) {
47 | return new LocalOssClient(localOssConfig);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/utils/OssPathUtil.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.utils;
2 |
3 | import cn.hutool.core.util.ObjectUtil;
4 | import cn.hutool.core.util.StrUtil;
5 | import lombok.extern.slf4j.Slf4j;
6 |
7 | /**
8 | * @author 陈敏
9 | * @version PathUtil.java, v 1.1 2022/2/18 17:01 chenmin Exp $
10 | * Created on 2022/2/18
11 | */
12 | @Slf4j
13 | public class OssPathUtil {
14 |
15 | public static String valid(String basePath) {
16 | // 根路径未配置时,默认路径为 /
17 | if (ObjectUtil.isEmpty(basePath)) {
18 | basePath = StrUtil.SLASH;
19 | }
20 | // 将路径分隔符统一转为 /
21 | basePath = basePath.replaceAll("\\\\", StrUtil.SLASH).replaceAll("//", StrUtil.SLASH);
22 |
23 | // 将配置默认转为绝对路径
24 | if (!basePath.startsWith(StrUtil.SLASH)) {
25 | basePath = StrUtil.SLASH + basePath;
26 | }
27 | if (!basePath.endsWith(StrUtil.SLASH)) {
28 | basePath = basePath + StrUtil.SLASH;
29 | }
30 | return basePath;
31 | }
32 |
33 | /**
34 | * 路径转换
35 | * 将路径分隔符转为统一的 / 分隔
36 | * @param key 路径
37 | * @param isAbsolute 是否绝对路径
38 | * true:绝对路径;false:相对路径
39 | * @return 以 / 为分隔的路径
40 | */
41 | public static String convertPath(String key, Boolean isAbsolute) {
42 | key = key.replaceAll("\\\\", StrUtil.SLASH).replaceAll("//", StrUtil.SLASH);
43 | if (isAbsolute && !key.startsWith(StrUtil.SLASH)) {
44 | key = StrUtil.SLASH + key;
45 | } else if (!isAbsolute && key.startsWith(StrUtil.SLASH)) {
46 | key = key.replaceFirst(StrUtil.SLASH, "");
47 | }
48 | return key;
49 | }
50 |
51 | /**
52 | * 获取相对根路径的绝对路径
53 | * @param path 全路径
54 | * @param basePath 根路径
55 | * @param isAbsolute 是否绝对路径
56 | * true:绝对路径;false:相对路径
57 | * @return 完整路径
58 | */
59 | public static String replaceKey(String path, String basePath, Boolean isAbsolute) {
60 | String newPath;
61 | if (StrUtil.SLASH.equals(basePath)) {
62 | newPath = convertPath(path, isAbsolute);
63 | } else {
64 | newPath = convertPath(path, isAbsolute).replaceAll(convertPath(basePath, isAbsolute), "");
65 | }
66 | return convertPath(newPath, isAbsolute);
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/sftp/SftpOssConfiguration.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.sftp;
2 |
3 | import cn.hutool.core.text.CharPool;
4 | import cn.hutool.extra.spring.SpringUtil;
5 | import cn.hutool.extra.ssh.Sftp;
6 | import com.jcraft.jsch.ChannelSftp;
7 | import io.github.artislong.constant.OssConstant;
8 | import io.github.artislong.core.StandardOssClient;
9 | import io.github.artislong.core.sftp.model.SftpOssConfig;
10 | import org.springframework.beans.factory.annotation.Autowired;
11 | import org.springframework.boot.SpringBootConfiguration;
12 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
13 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
14 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
15 | import org.springframework.context.annotation.Bean;
16 |
17 | import java.util.Map;
18 |
19 | /**
20 | * @author 陈敏
21 | * @version SftpOssConfiguration.java, v 1.1 2021/11/16 15:33 chenmin Exp $
22 | * Created on 2021/11/16
23 | */
24 | @SpringBootConfiguration
25 | @ConditionalOnClass(ChannelSftp.class)
26 | @EnableConfigurationProperties({SftpOssProperties.class})
27 | @ConditionalOnProperty(prefix = OssConstant.OSS, name = OssConstant.OssType.SFTP + CharPool.DOT + OssConstant.ENABLE,
28 | havingValue = OssConstant.DEFAULT_ENABLE_VALUE)
29 | public class SftpOssConfiguration {
30 |
31 | public static final String DEFAULT_BEAN_NAME = "sftpOssClient";
32 |
33 | @Autowired
34 | private SftpOssProperties sftpOssProperties;
35 |
36 | @Bean
37 | public StandardOssClient sftpOssClient() {
38 | Map sftpOssConfigMap = sftpOssProperties.getOssConfig();
39 | if (sftpOssConfigMap.isEmpty()) {
40 | SpringUtil.registerBean(DEFAULT_BEAN_NAME, sftpOssClient(sftpOssProperties));
41 | } else {
42 | sftpOssConfigMap.forEach((name, sftpOssConfig) -> SpringUtil.registerBean(name, sftpOssClient(sftpOssConfig)));
43 | }
44 | return null;
45 | }
46 |
47 | public StandardOssClient sftpOssClient(SftpOssConfig sftpOssConfig) {
48 | return new SftpOssClient(sftp(sftpOssConfig), sftpOssConfig);
49 | }
50 |
51 | public Sftp sftp(SftpOssConfig sftpOssConfig) {
52 | return new Sftp(sftpOssConfig.toFtpConfig());
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/wangyi/model/WangYiOssClientConfig.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.wangyi.model;
2 |
3 | import cn.hutool.core.bean.BeanUtil;
4 | import com.netease.cloud.ClientConfiguration;
5 | import com.netease.cloud.Protocol;
6 | import lombok.Data;
7 | import lombok.experimental.Accessors;
8 |
9 | import static com.netease.cloud.ClientConfiguration.*;
10 |
11 | /**
12 | * @author 陈敏
13 | * @version WangYiOssClientConfig.java, v 1.0 2022/4/21 10:17 chenmin Exp $
14 | * Created on 2022/4/21
15 | */
16 | @Data
17 | @Accessors(chain = true)
18 | public class WangYiOssClientConfig {
19 | /**
20 | * 连接超时时间
21 | */
22 | private int connectionTimeout = 50 * 1000;
23 | /**
24 | * 最大连接池大小。
25 | */
26 | private int maxConnections = DEFAULT_MAX_CONNECTIONS;
27 | /**
28 | * 最大失败重试次数
29 | */
30 | private int maxErrorRetry = DEFAULT_MAX_RETRIES;
31 | /**
32 | * 是否使用子域名
33 | */
34 | private boolean isSubDomain = true;
35 | /**
36 | * 连接OSS所采用的协议(HTTP或HTTPS),默认为HTTP。
37 | */
38 | private Protocol protocol = Protocol.HTTP;
39 | /**
40 | * 代理服务器的域,该域可以执行NTLM认证
41 | */
42 | private String proxyDomain;
43 | /**
44 | * 代理服务器主机地址
45 | */
46 | private String proxyHost;
47 | /**
48 | * 代理服务器验证的密码
49 | */
50 | private String proxyPassword;
51 | /**
52 | * 代理服务器端口
53 | */
54 | private int proxyPort = -1;
55 | /**
56 | * 代理服务器验证的用户名
57 | */
58 | private String proxyUsername;
59 | /**
60 | * 代理主机的NTLM身份验证服务器
61 | */
62 | private String proxyWorkstation;
63 | /**
64 | * Socket层传输数据的超时时间(单位:毫秒)。默认为50000毫秒。
65 | */
66 | private int socketTimeout = DEFAULT_SOCKET_TIMEOUT;
67 | /**
68 | * 用户代理,指HTTP的User-Agent头
69 | */
70 | private String userAgent = DEFAULT_USER_AGENT;
71 | /**
72 | * Socket接收缓冲区的大小提示(以字节为单位)。
73 | */
74 | private int socketReceiveBufferSizeHint = 0;
75 | /**
76 | * Socket发送缓冲区的大小提示(以字节为单位)。
77 | */
78 | private int socketSendBufferSizeHint = 0;
79 |
80 | public ClientConfiguration toClientConfig() {
81 | ClientConfiguration clientConfiguration = new ClientConfiguration();
82 | BeanUtil.copyProperties(this, clientConfiguration);
83 | return clientConfiguration;
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/jdbc/model/JdbcOssInfo.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.jdbc.model;
2 |
3 | import cn.hutool.core.convert.Convert;
4 | import cn.hutool.core.date.DatePattern;
5 | import cn.hutool.core.date.DateUtil;
6 | import cn.hutool.core.util.StrUtil;
7 | import io.github.artislong.core.jdbc.constant.JdbcOssConstant;
8 | import io.github.artislong.exception.NotSupportException;
9 | import io.github.artislong.model.DirectoryOssInfo;
10 | import io.github.artislong.model.FileOssInfo;
11 | import io.github.artislong.model.OssInfo;
12 | import io.github.artislong.utils.OssPathUtil;
13 | import lombok.Data;
14 | import lombok.experimental.Accessors;
15 |
16 | import java.util.Date;
17 |
18 | /**
19 | * @author 陈敏
20 | * @version JdbcOssInfo.java, v 1.0 2022/3/12 15:49 chenmin Exp $
21 | * Created on 2022/3/12
22 | */
23 | @Data
24 | @Accessors(chain = true)
25 | public class JdbcOssInfo {
26 | private String id;
27 | private String name;
28 | private String path;
29 | private Long size = 0L;
30 | private Date createTime;
31 | private Date lastUpdateTime;
32 | private String parentId;
33 | private String type;
34 | private String dataId;
35 |
36 | public OssInfo convertOssInfo(String basePath) {
37 | if (basePath.endsWith(StrUtil.SLASH)) {
38 | basePath = basePath.substring(0, basePath.length() - 1);
39 | }
40 |
41 | String key = this.getPath() + this.getName();
42 | String path = OssPathUtil.replaceKey(this.getPath(), basePath, true);
43 |
44 | OssInfo ossInfo;
45 | switch (this.getType()) {
46 | case JdbcOssConstant.OSS_TYPE.FILE:
47 | ossInfo = new FileOssInfo();
48 | ossInfo.setPath(path);
49 | ossInfo.setLength(Convert.toStr(this.getSize()));
50 | break;
51 | case JdbcOssConstant.OSS_TYPE.DIRECTORY:
52 | ossInfo = new DirectoryOssInfo();
53 | if (key.equals(basePath)) {
54 | ossInfo.setPath(StrUtil.SLASH);
55 | } else {
56 | ossInfo.setPath(path);
57 | }
58 | break;
59 | default:
60 | throw new NotSupportException("不支持的对象类型");
61 | }
62 |
63 | ossInfo.setName(this.getName());
64 | ossInfo.setCreateTime(DateUtil.date(this.getCreateTime()).toString(DatePattern.NORM_DATETIME_PATTERN));
65 | ossInfo.setLastUpdateTime(DateUtil.date(this.getLastUpdateTime()).toString(DatePattern.NORM_DATETIME_PATTERN));
66 | return ossInfo;
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/sftp/DefaultSftpProgressMonitor.java:
--------------------------------------------------------------------------------
1 | /**
* $Id: DefaultSftpProgressMonitor.java,v 1.0 2022/2/12 5:11 PM chenmin Exp $
*/
package io.github.artislong.core.sftp;
import com.jcraft.jsch.SftpProgressMonitor;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import java.text.NumberFormat;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
/**
* @author 陈敏
* @version $Id: DefaultSftpProgressMonitor.java,v 1.1 2022/2/12 5:11 PM chenmin Exp $
* Created on 2022/2/12 5:11 PM
* My blog: https://www.chenmin.info
*/
@Data
@Slf4j
@AllArgsConstructor
@NoArgsConstructor
public class DefaultSftpProgressMonitor implements SftpProgressMonitor, Runnable {
private long maxFileSize = 0L;
private long startTime = 0L;
private long upLoaded = 0L;
private boolean isScheduled = false;
private ScheduledExecutorService executorService;
public DefaultSftpProgressMonitor(long maxFileSize) {
this.maxFileSize = maxFileSize;
}
@Override
public void run() {
NumberFormat format = NumberFormat.getPercentInstance();
format.setMaximumFractionDigits(2);
format.setMinimumFractionDigits(2);
String value = format.format((upLoaded / (double) maxFileSize));
if (log.isDebugEnabled()) {
log.debug("已传输:{}KB,传输进度:{}", upLoaded/1024, value);
}
if (upLoaded == maxFileSize) {
destoryThread();
long endTime = System.currentTimeMillis();
if (log.isDebugEnabled()) {
log.debug("传输完成!用时:{}s", (endTime - startTime)/1000);
}
}
}
@Override
public void init(int op, String src, String dest, long max) {
if (log.isDebugEnabled()) {
log.debug("开始传输文件:{},文件总大小为:{}KB", src, maxFileSize/1024);
}
startTime = System.currentTimeMillis();
}
@Override
public boolean count(long count) {
if (!isScheduled) {
createThread();
}
upLoaded += count;
if (count > 0) {
return true;
}
return false;
}
@Override
public void end() {
}
/**
* 创建线程,定时输出上传进度
*/
public void createThread() {
executorService = Executors.newSingleThreadScheduledExecutor();
executorService.scheduleWithFixedDelay(this, 1, 2, TimeUnit.SECONDS);
isScheduled = true;
}
public void destoryThread() {
boolean isShutdown = executorService.isShutdown();
if (!isShutdown) {
executorService.shutdown();
}
}
}
--------------------------------------------------------------------------------
/docs/ftp/README.md:
--------------------------------------------------------------------------------
1 | ## 开始使用
2 |
3 | 引入以下依赖
4 |
5 | ```xml
6 |
7 | io.github.artislong
8 | oss-spring-boot-starter
9 | {latest.version}
10 |
11 |
12 | commons-net
13 | commons-net
14 | 3.8.0
15 |
16 | ```
17 |
18 | 通过`oss.ftp.enable=true`开启FTP自动配置
19 |
20 | ## 配置详解
21 |
22 | **注:**所有具有默认值的属性,配置都可缺省,且不支持复用。
23 |
24 | - 单个FTP配置
25 |
26 | ```yaml
27 | oss:
28 | ftp:
29 | enable: true
30 | host: FTP服务器IP
31 | port: FTP服务端口
32 | user: 用户名
33 | password: 密码
34 | charset: 编码
35 | base-path: FTP服务器存储根路径
36 | ```
37 |
38 | 通过如上配置即可开启FTP,可通过以下方式注入标准的OSS客户端。
39 |
40 | ```java
41 | @Autowired
42 | @Qualifier(FtpOssConfiguration.DEFAULT_BEAN_NAME)
43 | private StandardOssClient ossClient;
44 | ```
45 |
46 | - 多个FTP配置
47 |
48 | ```yaml
49 | oss:
50 | ftp:
51 | enable: true
52 | oss-config:
53 | ftpOssClient1:
54 | host: FTP服务器IP
55 | port: FTP服务端口
56 | user: 用户名
57 | password: 密码
58 | charset: 编码
59 | base-path: FTP服务器存储根路径
60 | ftpOssClient2:
61 | host: FTP服务器IP
62 | port: FTP服务端口
63 | user: 用户名
64 | password: 密码
65 | charset: 编码
66 | base-path: FTP服务器存储根路径
67 | ```
68 |
69 | 当配置多个FTP时,使用如下方式注入
70 |
71 | ```java
72 | @Autowired
73 | @Qualifier("ftpOssClient1")
74 | private StandardOssClient ftpOssClient1;
75 | @Autowired
76 | @Qualifier("ftpOssClient2")
77 | private StandardOssClient ftpOssClient2;
78 | ```
79 |
80 | - 客户端自定义配置
81 |
82 | 可通过oss.ftp.client-config.XXX来配置,XXX具体值可通过`io.github.artislong.core.ftp.model.FtpOssClientConfig`类查看。
83 |
84 | 
85 |
86 | 示例如下:
87 |
88 | ```yaml
89 | oss:
90 | ftp:
91 | enable: true
92 | host: FTP服务器IP
93 | port: FTP服务端口
94 | user: 用户名
95 | password: 密码
96 | charset: 编码
97 | base-path: FTP服务器存储根路径
98 | client-config:
99 | mode: Passive
100 | back-to-pwd: false
101 | # ......
102 | ```
103 |
104 | - 配置复用
105 |
106 | 由于FTP服务不同于标准的OSS对象存储,所以基本配置不支持复用,仅对client-config属性进行复用配置支持。
107 |
108 | ```yaml
109 | oss:
110 | ftp:
111 | enable: true
112 | client-config:
113 | mode: Passive
114 | back-to-pwd: false
115 | # ......
116 | oss-config:
117 | ftpOssClient1:
118 | host: FTP服务器IP
119 | port: FTP服务端口
120 | user: 用户名
121 | password: 密码
122 | charset: 编码
123 | base-path: FTP服务器存储根路径
124 | ftpOssClient2:
125 | host: FTP服务器IP
126 | port: FTP服务端口
127 | user: 用户名
128 | password: 密码
129 | charset: 编码
130 | base-path: FTP服务器存储根路径
131 | ```
132 |
133 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/ftp/FtpOssConfiguration.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.ftp;
2 |
3 | import cn.hutool.core.text.CharPool;
4 | import cn.hutool.core.util.ObjectUtil;
5 | import cn.hutool.extra.ftp.Ftp;
6 | import cn.hutool.extra.spring.SpringUtil;
7 | import io.github.artislong.constant.OssConstant;
8 | import io.github.artislong.core.StandardOssClient;
9 | import io.github.artislong.core.ftp.model.FtpOssClientConfig;
10 | import io.github.artislong.core.ftp.model.FtpOssConfig;
11 | import org.apache.commons.net.ftp.FTPClient;
12 | import org.springframework.beans.factory.annotation.Autowired;
13 | import org.springframework.boot.SpringBootConfiguration;
14 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
15 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
16 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
17 | import org.springframework.context.annotation.Bean;
18 |
19 | import java.util.Map;
20 | import java.util.Optional;
21 |
22 | /**
23 | * @author 陈敏
24 | * @version FtpOssConfiguration.java, v 1.1 2021/11/16 15:29 chenmin Exp $
25 | * Created on 2021/11/16
26 | */
27 | @SpringBootConfiguration
28 | @ConditionalOnClass(FTPClient.class)
29 | @EnableConfigurationProperties({FtpOssProperties.class})
30 | @ConditionalOnProperty(prefix = OssConstant.OSS, name = OssConstant.OssType.FTP + CharPool.DOT + OssConstant.ENABLE,
31 | havingValue = OssConstant.DEFAULT_ENABLE_VALUE)
32 | public class FtpOssConfiguration {
33 |
34 | public static final String DEFAULT_BEAN_NAME = "ftpOssClient";
35 |
36 | @Autowired
37 | private FtpOssProperties ftpOssProperties;
38 |
39 | @Bean
40 | public StandardOssClient ftpOssClient() {
41 | Map ftpOssConfigMap = ftpOssProperties.getOssConfig();
42 | if (ftpOssConfigMap.isEmpty()) {
43 | SpringUtil.registerBean(DEFAULT_BEAN_NAME, ftpOssClient(ftpOssProperties));
44 | } else {
45 | FtpOssClientConfig clientConfig = ftpOssProperties.getClientConfig();
46 | ftpOssConfigMap.forEach((name, ftpOssConfig) -> {
47 | if (ObjectUtil.isEmpty(ftpOssConfig.getClientConfig())) {
48 | ftpOssConfig.setClientConfig(clientConfig);
49 | }
50 | SpringUtil.registerBean(name, ftpOssClient(ftpOssConfig));
51 | });
52 | }
53 | return null;
54 | }
55 |
56 | public StandardOssClient ftpOssClient(FtpOssConfig ftpOssConfig) {
57 | return new FtpOssClient(ftp(ftpOssConfig), ftpOssConfig);
58 | }
59 |
60 | public Ftp ftp(FtpOssConfig ftpOssConfig) {
61 | FtpOssClientConfig clientConfig = Optional.ofNullable(ftpOssConfig.getClientConfig()).orElse(new FtpOssClientConfig());
62 | Ftp ftp = new Ftp(ftpOssConfig.toFtpConfig(), clientConfig.getMode());
63 | ftp.setBackToPwd(clientConfig.isBackToPwd());
64 | return ftp;
65 | }
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/docs/sftp/README.md:
--------------------------------------------------------------------------------
1 | ## 开始使用
2 |
3 | 引入以下依赖
4 |
5 | ```xml
6 |
7 | io.github.artislong
8 | oss-spring-boot-starter
9 | {latest.version}
10 |
11 |
12 | com.jcraft
13 | jsch
14 | 0.1.55
15 |
16 | ```
17 |
18 | 通过`oss.sftp.enable=true`开启FTP自动配置
19 |
20 | ## 配置详解
21 |
22 | **注:**所有具有默认值的属性,配置都可缺省,且不支持复用。
23 |
24 | - 单个SFTP配置
25 |
26 | ```yaml
27 | oss:
28 | sftp:
29 | enable: true
30 | host: SFTP服务器IP
31 | port: SFTP服务端口
32 | user: 用户名
33 | password: 密码
34 | charset: 编码
35 | base-path: FTP服务器存储根路径
36 | ```
37 |
38 | 通过如上配置即可开启SFTP,可通过以下方式注入标准的OSS客户端。
39 |
40 | ```java
41 | @Autowired
42 | @Qualifier(SftpOssConfiguration.DEFAULT_BEAN_NAME)
43 | private StandardOssClient ossClient;
44 | ```
45 |
46 | - 多个FTP配置
47 |
48 | ```yaml
49 | oss:
50 | sftp:
51 | enable: true
52 | oss-config:
53 | sftpOssClient1:
54 | host: SFTP服务器IP
55 | port: SFTP服务端口
56 | user: 用户名
57 | password: 密码
58 | charset: 编码
59 | base-path: SFTP服务器存储根路径
60 | sftpOssClient2:
61 | host: SFTP服务器IP
62 | port: SFTP服务端口
63 | user: 用户名
64 | password: 密码
65 | charset: 编码
66 | base-path: SFTP服务器存储根路径
67 | ```
68 |
69 | 当配置多个SFTP时,使用如下方式注入
70 |
71 | ```java
72 | @Autowired
73 | @Qualifier("sftpOssClient1")
74 | private StandardOssClient sftpOssClient1;
75 | @Autowired
76 | @Qualifier("sftpOssClient2")
77 | private StandardOssClient sftpOssClient2;
78 | ```
79 |
80 | - 客户端自定义配置
81 |
82 | 可通过oss.sftp.client-config.XXX来配置,XXX具体值可通过`io.github.artislong.core.sftp.model.SftpOssClientConfig`类查看。
83 |
84 | 
85 |
86 | 示例如下:
87 |
88 | ```yaml
89 | oss:
90 | sftp:
91 | enable: true
92 | host: SFTP服务器IP
93 | port: SFTP服务端口
94 | user: 用户名
95 | password: 密码
96 | charset: 编码
97 | base-path: SFTP服务器存储根路径
98 | client-config:
99 | connection-timeout: 10000
100 | so-timeout: 10000
101 | # ......
102 | ```
103 |
104 | - 配置复用
105 |
106 | 由于SFTP服务不同于标准的OSS对象存储,所以基本配置不支持复用,仅对client-config属性进行复用配置支持。
107 |
108 | ```yaml
109 | oss:
110 | sftp:
111 | enable: true
112 | client-config:
113 | connection-timeout: 10000
114 | so-timeout: 10000
115 | # ......
116 | oss-config:
117 | sftpOssClient1:
118 | host: FTP服务器IP
119 | port: SFTP服务端口
120 | user: 用户名
121 | password: 密码
122 | charset: 编码
123 | base-path: SFTP服务器存储根路径
124 | sftpOssClient2:
125 | host: SFTP服务器IP
126 | port: SFTP服务端口
127 | user: 用户名
128 | password: 密码
129 | charset: 编码
130 | base-path: SFTP服务器存储根路径
131 | ```
132 |
133 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/tencent/model/TencentOssClientConfig.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.tencent.model;
2 |
3 | import cn.hutool.core.bean.BeanUtil;
4 | import cn.hutool.core.bean.copier.CopyOptions;
5 | import cn.hutool.core.util.ObjectUtil;
6 | import com.qcloud.cos.ClientConfig;
7 | import com.qcloud.cos.http.HttpProtocol;
8 | import com.qcloud.cos.region.Region;
9 | import lombok.Data;
10 | import lombok.experimental.Accessors;
11 |
12 | import static io.github.artislong.core.tencent.constant.TencentOssConstant.*;
13 |
14 | /**
15 | * @author 陈敏
16 | * @version TencentOssClientConfig.java, v 1.0 2022/4/19 19:58 chenmin Exp $
17 | * Created on 2022/4/19
18 | */
19 | @Data
20 | @Accessors(chain = true)
21 | public class TencentOssClientConfig {
22 | /**
23 | * 地域
24 | */
25 | private String region;
26 | /**
27 | * 连接OSS所采用的协议(HTTP或HTTPS),默认为HTTPS。
28 | */
29 | private HttpProtocol httpProtocol = HttpProtocol.https;
30 | /**
31 | * 域名后缀
32 | */
33 | private String endPointSuffix = null;
34 | /**
35 | * http proxy代理,如果使用http proxy代理,需要设置IP与端口
36 | */
37 | private String httpProxyIp = null;
38 | /**
39 | * 代理服务器端口
40 | */
41 | private int httpProxyPort = 0;
42 | /**
43 | * 代理服务器验证的用户名。
44 | */
45 | private String proxyUsername = null;
46 | /**
47 | * 代理服务器验证的密码。
48 | */
49 | private String proxyPassword = null;
50 | /**
51 | * 是否使用基本身份验证
52 | */
53 | private boolean useBasicAuth = false;
54 | /**
55 | * 多次签名的过期时间,单位秒
56 | */
57 | private long signExpired = DEFAULT_SIGN_EXPIRED;
58 | /**
59 | * 获取连接的超时时间, 单位ms
60 | */
61 | private int connectionRequestTimeout = DEFAULT_CONNECTION_REQUEST_TIMEOUT;
62 | /**
63 | * 默认连接超时, 单位ms
64 | */
65 | private int connectionTimeout = DEFAULT_CONNECTION_TIMEOUT;
66 | /**
67 | * SOCKET读取超时时间, 单位ms
68 | */
69 | private int socketTimeout = DEFAULT_SOCKET_TIMEOUT;
70 | /**
71 | * 最大HTTP连接数
72 | */
73 | private int maxConnectionsCount = DEFAULT_MAX_CONNECTIONS_COUNT;
74 | /**
75 | * 空闲连接存活时间
76 | */
77 | private int idleConnectionAlive = DEFAULT_IDLE_CONNECTION_ALIVE;
78 | /**
79 | * user_agent标识
80 | */
81 | private String userAgent = DEFAULT_USER_AGENT;
82 | /**
83 | * 读取限制
84 | */
85 | private int readLimit = DEFAULT_READ_LIMIT;
86 | /**
87 | * 数据万象特殊请求配置
88 | */
89 | private boolean ciSpecialRequest = false;
90 | /**
91 | * 请求失败后最大的重试次数。默认3次。
92 | **/
93 | private int maxErrorRetry = DEFAULT_RETRY_TIMES;
94 |
95 | public ClientConfig toClientConfig() {
96 | ClientConfig clientConfig = new ClientConfig();
97 | BeanUtil.copyProperties(this, clientConfig, new CopyOptions().setIgnoreNullValue(true).setIgnoreProperties("region"));
98 | if (ObjectUtil.isNotEmpty(region)) {
99 | clientConfig.setRegion(new Region(region));
100 | }
101 | return clientConfig;
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/docs/qiniu/README.md:
--------------------------------------------------------------------------------
1 | ## 开始使用
2 |
3 | 引入以下依赖
4 |
5 | ```xml
6 |
7 | io.github.artislong
8 | oss-spring-boot-starter
9 | {latest.version}
10 |
11 |
12 | com.qiniu
13 | qiniu-java-sdk
14 | 7.9.3
15 |
16 |
17 | com.qiniu
18 | happy-dns-java
19 | 0.1.6
20 |
21 | ```
22 |
23 | 通过`oss.qiniu.enable=true`开启七牛云OSS对象存储自动配置
24 |
25 | ## 配置详解
26 |
27 | **注:**所有具有默认值的属性,配置都可缺省,且不支持复用。
28 |
29 | - 单个七牛云OSS对象存储配置
30 |
31 | ```yaml
32 | oss:
33 | qiniu:
34 | qiniu:
35 | enable: true
36 | access-key: AccessKey
37 | secret-key: SecretKey
38 | bucket-name: Bucket
39 | base-path: /
40 | slice-config:
41 | task-num: 8
42 | part-size: 104857600
43 | ```
44 |
45 | 通过如上配置即可开启七牛云OSS对象存储,可通过以下方式注入标准的OSS客户端。
46 |
47 | ```java
48 | @Autowired
49 | @Qualifier(QiniuOssConfiguration.DEFAULT_BEAN_NAME)
50 | private StandardOssClient ossClient;
51 | ```
52 |
53 | - 多个七牛云OSS对象存储配置
54 |
55 | ```yaml
56 | oss:
57 | qiniu:
58 | enable: true
59 | oss-config:
60 | qiniuOssClient1:
61 | access-key: AccessKey
62 | secret-key: SecretKey
63 | bucket-name: Bucket
64 | base-path: /
65 | slice-config:
66 | task-num: 8
67 | part-size: 104857600
68 | qiniuOssClient2:
69 | access-key: AccessKey
70 | secret-key: SecretKey
71 | bucket-name: Bucket
72 | base-path: /
73 | slice-config:
74 | task-num: 8
75 | part-size: 104857600
76 | ```
77 |
78 | 当配置多个七牛云OSS对象存储时,使用如下方式注入
79 |
80 | ```java
81 | @Autowired
82 | @Qualifier("qiniuOssClient1")
83 | private StandardOssClient qiniuOssClient1;
84 | @Autowired
85 | @Qualifier("qiniuOssClient2")
86 | private StandardOssClient qiniuOssClient2;
87 | ```
88 |
89 | - 客户端自定义配置
90 |
91 | 可通过oss.qiniu.client-config.XXX来配置,XXX具体值可通过`io.github.artislong.core.qiniu.model.QiniuOssClientConfig`类查看。
92 |
93 | 
94 |
95 | 示例如下:
96 |
97 | ```yaml
98 | oss:
99 | qiniu:
100 | enable: true
101 | access-key: AccessKey
102 | secret-key: SecretKey
103 | bucket-name: Bucket
104 | base-path: /
105 | slice-config:
106 | task-num: 8
107 | part-size: 104857600
108 | client-config:
109 | connect-timeout: 60
110 | write-timeout: 100
111 | read-timeout: 100
112 | # ......
113 | ```
114 |
115 | - 配置复用
116 |
117 | 当使用同一个七牛云OSS对象存储多个不同Bucket时,可复用accessKey、secretKey,只需要配置Bucket相关参数即可,示例如下:
118 |
119 | ```yaml
120 | oss:
121 | qiniu:
122 | enable: true
123 | access-key: AccessKey
124 | secret-key: SecretKey
125 | slice-config:
126 | task-num: 8
127 | part-size: 104857600
128 | oss-config:
129 | qiniuOssClient1:
130 | bucket-name: Bucket1
131 | qiniuOssClient2:
132 | bucket-name: Bucket2
133 | ```
134 |
135 |
--------------------------------------------------------------------------------
/docs/huawei/README.md:
--------------------------------------------------------------------------------
1 | ## 开始使用
2 |
3 | 引入以下依赖
4 |
5 | ```xml
6 |
7 | io.github.artislong
8 | oss-spring-boot-starter
9 | {latest.version}
10 |
11 |
12 | com.huaweicloud
13 | esdk-obs-java-bundle
14 | 3.21.11
15 |
16 | ```
17 |
18 | 通过`oss.huawei.enable=true`开启华为云OSS对象存储自动配置
19 |
20 | ## 配置详解
21 |
22 | **注:**所有具有默认值的属性,配置都可缺省,且不支持复用。
23 |
24 | - 单个华为云OSS对象存储配置
25 |
26 | ```yaml
27 | oss:
28 | huawei:
29 | enable: true
30 | access-key: AccessKey
31 | secret-key: SecretKey
32 | end-point: EndPoint
33 | bucket-name: Bucket
34 | base-path: /
35 | slice-config:
36 | task-num: 8
37 | part-size: 104857600
38 | ```
39 |
40 | 通过如上配置即可开启华为云OSS对象存储,可通过以下方式注入标准的OSS客户端。
41 |
42 | ```java
43 | @Autowired
44 | @Qualifier(BaiduOssConfiguration.DEFAULT_BEAN_NAME)
45 | private StandardOssClient ossClient;
46 | ```
47 |
48 | - 多个华为云OSS对象存储配置
49 |
50 | ```yaml
51 | oss:
52 | huawei:
53 | enable: true
54 | oss-config:
55 | huaweiOssClient1:
56 | access-key: AccessKey
57 | secret-key: SecretKey
58 | end-point: EndPoint
59 | bucket-name: Bucket
60 | base-path: /
61 | slice-config:
62 | task-num: 8 # 并发线程数,默认等于CPU的核数
63 | part-size: 104857600 # 分片大小,单位KB,默认5MB
64 | huaweiOssClient2:
65 | access-key: AccessKey
66 | secret-key: SecretKey
67 | end-point: EndPoint
68 | bucket-name: Bucket
69 | base-path: /
70 | slice-config:
71 | task-num: 8 # 并发线程数,默认等于CPU的核数
72 | part-size: 104857600 # 分片大小,单位KB,默认5MB
73 | ```
74 |
75 | 当配置多个华为云OSS对象存储时,使用如下方式注入
76 |
77 | ```java
78 | @Autowired
79 | @Qualifier("huaweiOssClient1")
80 | private StandardOssClient huaweiOssClient1;
81 | @Autowired
82 | @Qualifier("huaweiOssClient2")
83 | private StandardOssClient huaweiOssClient2;
84 | ```
85 |
86 | - 客户端自定义配置
87 |
88 | 可通过oss.huawei.client-config.XXX来配置,XXX具体值可通过`io.github.artislong.core.huawei.model.HuaWeiOssClientConfig`类查看。
89 |
90 | 
91 |
92 | 示例如下:
93 |
94 | ```yaml
95 | oss:
96 | huawei:
97 | enable: true
98 | access-key: AccessKey
99 | secret-key: SecretKey
100 | end-point: EndPoint
101 | bucket-name: Bucket
102 | base-path: /
103 | client-config:
104 | connection-timeout: 50000
105 | max-connections: 50
106 | # ......
107 | ```
108 |
109 | - 配置复用
110 |
111 | 当使用同一个华为云OSS对象存储多个不同Bucket时,可复用accessKey、secretKey,endPoint、clientConfig,只需要配置Bucket相关参数即可,示例如下:
112 |
113 | ```yaml
114 | oss:
115 | huawei:
116 | enable: true
117 | access-key: AccessKey
118 | secret-key: SecretKey
119 | end-point: EndPoint
120 | slice-config:
121 | task-num: 8
122 | part-size: 104857600
123 | oss-config:
124 | huaweiOssClient1:
125 | bucket-name: Bucket1
126 | huaweiOssClient2:
127 | bucket-name: Bucket2
128 | ```
129 |
130 |
--------------------------------------------------------------------------------
/docs/qingyun/README.md:
--------------------------------------------------------------------------------
1 | ## 开始使用
2 |
3 | 引入以下依赖
4 |
5 | ```xml
6 |
7 | io.github.artislong
8 | oss-spring-boot-starter
9 | {latest.version}
10 |
11 |
12 | com.yunify
13 | qingstor.sdk.java
14 | 2.5.2
15 |
16 | ```
17 |
18 | 通过`oss.qingyun.enable=true`开启青云OSS对象存储自动配置
19 |
20 | ## 配置详解
21 |
22 | **注:**所有具有默认值的属性,配置都可缺省,且不支持复用。
23 |
24 | - 单个青云OSS对象存储配置
25 |
26 | ```yaml
27 | oss:
28 | qingyun:
29 | enable: true
30 | zone: Zone
31 | access-key: AccessKey
32 | access-secret: AccessSecret
33 | bucket-name: Bucket
34 | base-path: /
35 | slice-config:
36 | task-num: 8
37 | part-size: 104857600
38 | ```
39 |
40 | 通过如上配置即可开启青云OSS对象存储,可通过以下方式注入标准的OSS客户端。
41 |
42 | ```java
43 | @Autowired
44 | @Qualifier(QingYunOssConfiguration.DEFAULT_BEAN_NAME)
45 | private StandardOssClient ossClient;
46 | ```
47 |
48 | - 多个青云OSS对象存储配置
49 |
50 | ```yaml
51 | oss:
52 | qingyun:
53 | enable: true
54 | oss-config:
55 | qingyunOssClient1:
56 | zone: Zone
57 | access-key: AccessKey
58 | access-secret: AccessSecret
59 | bucket-name: Bucket1
60 | base-path: /
61 | slice-config:
62 | task-num: 8
63 | part-size: 104857600
64 | qingyunOssClient2:
65 | zone: Zone
66 | access-key: AccessKey
67 | access-secret: AccessSecret
68 | bucket-name: Bucket2
69 | base-path: /
70 | slice-config:
71 | task-num: 8
72 | part-size: 104857600
73 | ```
74 |
75 | 当配置多个青云OSS对象存储时,使用如下方式注入
76 |
77 | ```java
78 | @Autowired
79 | @Qualifier("qingyunOssClient1")
80 | private StandardOssClient qingyunOssClient1;
81 | @Autowired
82 | @Qualifier("qingyunOssClient2")
83 | private StandardOssClient qingyunOssClient2;
84 | ```
85 |
86 | - 客户端自定义配置
87 |
88 | 可通过oss.qingyun.client-config.XXX来配置,XXX具体值可通过`io.github.artislong.core.qingyun.model.QingYunOssClientConfig`类查看。
89 |
90 | 
91 |
92 | 示例如下:
93 |
94 | ```yaml
95 | oss:
96 | qingyun:
97 | enable: true
98 | zone: Zone
99 | access-key: AccessKey
100 | access-secret: AccessSecret
101 | bucket-name: Bucket
102 | base-path: /
103 | slice-config:
104 | task-num: 8
105 | part-size: 104857600
106 | client-config:
107 | connection-timeout: 60
108 | write-timeout: 100
109 | read-timeout: 100
110 | # ......
111 | ```
112 |
113 | - 配置复用
114 |
115 | 当使用同一个青云OSS对象存储多个不同Bucket时,可复用zone、endpoint、accessKey、accessSecret,只需要配置Bucket相关参数即可,示例如下:
116 |
117 | ```yaml
118 | oss:
119 | qingyun:
120 | enable: true
121 | zone: Zone
122 | access-key: AccessKey
123 | access-secret: AccessSecret
124 | slice-config:
125 | task-num: 8
126 | part-size: 104857600
127 | oss-config:
128 | qingyunOssClient1:
129 | bucket-name: Bucket1
130 | qingyunOssClient2:
131 | bucket-name: Bucket2
132 | ```
133 |
134 |
--------------------------------------------------------------------------------
/docs/ali/README.md:
--------------------------------------------------------------------------------
1 | ## 开始使用
2 |
3 | 引入以下依赖
4 |
5 | ```xml
6 |
7 | io.github.artislong
8 | oss-spring-boot-starter
9 | {latest.version}
10 |
11 |
12 | com.aliyun.oss
13 | aliyun-sdk-oss
14 | 3.13.2
15 |
16 | ```
17 |
18 | 通过`oss.ali.enable=true`开启阿里云OSS对象存储自动配置
19 |
20 | ## 配置详解
21 |
22 | **注:**所有具有默认值的属性,配置都可缺省,且不支持复用。
23 |
24 | - 单个阿里云OSS对象存储配置
25 |
26 | ```yaml
27 | oss:
28 | ali:
29 | enable: true
30 | access-key-id: AccessKeyId
31 | access-key-secret: AccessKeySecret
32 | endpoint: Endpoint
33 | bucket-name: Bucket
34 | base-path: / # 存储根路径,默认路径为 /
35 | slice-config:
36 | task-num: 8 # 并发线程数,默认等于CPU的核数
37 | part-size: 104857600 # 分片大小,单位KB,默认5MB
38 | ```
39 |
40 | 通过如上配置即可开启阿里云OSS对象存储,可通过以下方式注入标准的OSS客户端。
41 |
42 | ```java
43 | @Autowired
44 | @Qualifier(AliOssConfiguration.DEFAULT_BEAN_NAME)
45 | private StandardOssClient ossClient;
46 | ```
47 |
48 | - 多个阿里云OSS对象存储配置
49 |
50 | ```yaml
51 | oss:
52 | ali:
53 | enable: true
54 | oss-config:
55 | aliOssClient1:
56 | access-key-id: AccessKeyId1
57 | access-key-secret: AccessKeySecret1
58 | endpoint: Endpoint1
59 | bucket-name: Bucket1
60 | base-path: / # 存储根路径,默认路径为 /
61 | slice-config:
62 | task-num: 8 # 并发线程数,默认等于CPU的核数
63 | part-size: 104857600 # 分片大小,单位KB,默认5MB
64 | aliOssClient2:
65 | access-key-id: AccessKeyId2
66 | access-key-secret: AccessKeySecret2
67 | endpoint: Endpoint2
68 | bucket-name: Bucket2
69 | base-path: / # 存储根路径,默认路径为 /
70 | slice-config:
71 | task-num: 8 # 并发线程数,默认等于CPU的核数
72 | part-size: 104857600 # 分片大小,单位KB,默认5MB
73 | ```
74 |
75 | 当配置多个阿里云OSS对象存储时,使用如下方式注入
76 |
77 | ```java
78 | @Autowired
79 | @Qualifier("aliOssClient1")
80 | private StandardOssClient aliOssClient1;
81 | @Autowired
82 | @Qualifier("aliOssClient2")
83 | private StandardOssClient aliOssClient2;
84 | ```
85 |
86 | - 客户端自定义配置
87 |
88 | 可通过oss.ali.client-config.XXX来配置,XXX具体值可通过`io.github.artislong.core.ali.model.AliOssClientConfig`类查看。
89 |
90 | 
91 |
92 | 示例如下:
93 |
94 | ```yaml
95 | oss:
96 | ali:
97 | enable: true
98 | access-key-id: AccessKeyId
99 | access-key-secret: AccessKeySecret
100 | endpoint: Endpoint
101 | bucket-name: Bucket
102 | client-config:
103 | socket-timeout: 50000
104 | connection-timeout: 50000
105 | # ......
106 | ```
107 |
108 | - 配置复用
109 |
110 | 当使用同一个阿里云对象存储多个不同Bucket时,可复用endpoint、accessKeyId、accessKeySecret、clientConfig,只需要配置Bucket相关参数即可,示例如下:
111 |
112 | ```yaml
113 | oss:
114 | ali:
115 | enable: true
116 | access-key-id: AccessKeyId
117 | access-key-secret: AccessKeySecret
118 | endpoint: Endpoint
119 | oss-config:
120 | aliOssClient1:
121 | bucket-name: Bucket1
122 | aliOssClient2:
123 | bucket-name: Bucket2
124 | ```
125 |
126 |
--------------------------------------------------------------------------------
/docs/up/README.md:
--------------------------------------------------------------------------------
1 | ## 开始使用
2 |
3 | 引入以下依赖
4 |
5 | ```xml
6 |
7 | io.github.artislong
8 | oss-spring-boot-starter
9 | {latest.version}
10 |
11 |
12 | com.upyun
13 | java-sdk
14 | 4.2.3
15 | provided
16 |
17 |
18 | com.github.tobato
19 | fastdfs-client
20 | 1.27.2
21 | provided
22 |
23 | ```
24 |
25 | 通过`oss.up.enable=true`开启又拍云OSS对象存储自动配置
26 |
27 | ## 配置详解
28 |
29 | **注:**所有具有默认值的属性,配置都可缺省,且不支持复用。
30 |
31 | - 单个又拍云OSS对象存储配置
32 |
33 | ```yaml
34 | oss:
35 | up:
36 | enable: true
37 | user-name: UserName
38 | password: Password
39 | bucket-name: Bucket
40 | base-path: /
41 | slice-config:
42 | task-num: 8
43 | part-size: 104857600
44 | ```
45 |
46 | 通过如上配置即可开启又拍云OSS对象存储,可通过以下方式注入标准的OSS客户端。
47 |
48 | ```java
49 | @Autowired
50 | @Qualifier(UpOssConfiguration.DEFAULT_BEAN_NAME)
51 | private StandardOssClient ossClient;
52 | ```
53 |
54 | - 多个又拍云OSS对象存储配置
55 |
56 | ```yaml
57 | oss:
58 | up:
59 | enable: true
60 | oss-config:
61 | upOssClient1:
62 | user-name: UserName
63 | password: Password
64 | bucket-name: Bucket1
65 | base-path: / # 存储根路径,默认路径为 /
66 | slice-config:
67 | task-num: 8 # 并发线程数,默认等于CPU的核数
68 | part-size: 104857600 # 分片大小,单位KB,默认5MB
69 | upOssClient2:
70 | user-name: UserName
71 | password: Password
72 | bucket-name: Bucket2
73 | base-path: / # 存储根路径,默认路径为 /
74 | slice-config:
75 | task-num: 8 # 并发线程数,默认等于CPU的核数
76 | part-size: 104857600 # 分片大小,单位KB,默认5MB
77 | ```
78 |
79 | 当配置多个又拍云OSS对象存储时,使用如下方式注入
80 |
81 | ```java
82 | @Autowired
83 | @Qualifier("upOssClient1")
84 | private StandardOssClient upOssClient1;
85 | @Autowired
86 | @Qualifier("upOssClient2")
87 | private StandardOssClient upOssClient2;
88 | ```
89 |
90 | - 客户端自定义配置
91 |
92 | 可通过oss.up.client-config.XXX来配置,XXX具体值可通过`io.github.artislong.core.up.model.UpOssClientConfig`类查看。
93 |
94 | 
95 |
96 | 示例如下:
97 |
98 | ```yaml
99 | oss:
100 | up:
101 | enable: true
102 | user-name: UserName
103 | password: Password
104 | bucket-name: Bucket
105 | base-path: / # 存储根路径,默认路径为 /
106 | client-config:
107 | timeout: 30
108 | api-domain: ED_AUTO
109 | # ......
110 | ```
111 |
112 | - 配置复用
113 |
114 | 当使用同一个又拍云OSS对象存储多个不同Bucket时,可复用userName、password、clientConfig,只需要配置Bucket相关参数即可,示例如下:
115 |
116 | ```yaml
117 | oss:
118 | up:
119 | enable: true
120 | user-name: UserName
121 | password: Password
122 | client-config:
123 | timeout-connect: 50000
124 | timeout-read: 50000
125 | # ......
126 | oss-config:
127 | upOssClient1:
128 | bucket-name: Bucket1
129 | upOssClient2:
130 | bucket-name: Bucket2
131 | ```
132 |
133 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/qiniu/model/QiNiuOssClientConfig.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.qiniu.model;
2 |
3 | import com.qiniu.common.Constants;
4 | import com.qiniu.storage.Configuration;
5 | import io.github.artislong.core.qiniu.constant.QiNiuRegion;
6 | import lombok.Data;
7 | import lombok.experimental.Accessors;
8 |
9 | /**
10 | * @author 陈敏
11 | * @version QiNiuOssClientConfig.java, v 1.0 2022/4/20 18:23 chenmin Exp $
12 | * Created on 2022/4/20
13 | */
14 | @Data
15 | @Accessors(chain = true)
16 | public class QiNiuOssClientConfig {
17 |
18 | /**
19 | * 使用的Region
20 | */
21 | public QiNiuRegion region = QiNiuRegion.AUTOREGION;
22 | /**
23 | * 空间相关上传管理操作是否使用 https , 默认 是
24 | */
25 | public boolean useHttpsDomains = true;
26 | /**
27 | * 空间相关上传管理操作是否使用代理加速上传,默认 是
28 | */
29 | public boolean accUpHostFirst = true;
30 | /**
31 | * 使用 AutoRegion 时,如果从区域信息得到上传 host 失败,使用默认的上传域名上传,默认 是
32 | * upload.qiniup.com, upload-z1.qiniup.com, upload-z2.qiniup.com,
33 | * upload-na0.qiniup.com, upload-as0.qiniup.com
34 | */
35 | public boolean useDefaultUpHostIfNone = true;
36 | /**
37 | * 如果文件大小大于此值则使用断点上传, 否则使用Form上传
38 | */
39 | public int putThreshold = Constants.BLOCK_SIZE;
40 | /**
41 | * 连接超时时间 单位秒(默认10s)
42 | */
43 | public int connectTimeout = Constants.CONNECT_TIMEOUT;
44 | /**
45 | * 写超时时间 单位秒(默认 0 , 不超时)
46 | */
47 | public int writeTimeout = Constants.WRITE_TIMEOUT;
48 | /**
49 | * 回复超时时间 单位秒(默认30s)
50 | */
51 | public int readTimeout = Constants.READ_TIMEOUT;
52 | /**
53 | * 底层HTTP库所有的并发执行的请求数量
54 | */
55 | public int dispatcherMaxRequests = Constants.DISPATCHER_MAX_REQUESTS;
56 | /**
57 | * 底层HTTP库对每个独立的Host进行并发请求的数量
58 | */
59 | public int dispatcherMaxRequestsPerHost = Constants.DISPATCHER_MAX_REQUESTS_PER_HOST;
60 | /**
61 | * 底层HTTP库中复用连接对象的最大空闲数量
62 | */
63 | public int connectionPoolMaxIdleCount = Constants.CONNECTION_POOL_MAX_IDLE_COUNT;
64 | /**
65 | * 底层HTTP库中复用连接对象的回收周期(单位分钟)
66 | */
67 | public int connectionPoolMaxIdleMinutes = Constants.CONNECTION_POOL_MAX_IDLE_MINUTES;
68 | /**
69 | * 上传失败重试次数
70 | */
71 | public int retryMax = 5;
72 |
73 | public Configuration toClientConfig() {
74 | Configuration configuration = new Configuration();
75 | configuration.region = this.region.buildRegion();
76 | configuration.useHttpsDomains = useHttpsDomains;
77 | configuration.accUpHostFirst = accUpHostFirst;
78 | configuration.useDefaultUpHostIfNone = useDefaultUpHostIfNone;
79 | configuration.putThreshold = putThreshold;
80 | configuration.connectTimeout = connectTimeout;
81 | configuration.writeTimeout = writeTimeout;
82 | configuration.readTimeout = readTimeout;
83 | configuration.dispatcherMaxRequests = dispatcherMaxRequests;
84 | configuration.dispatcherMaxRequestsPerHost = dispatcherMaxRequestsPerHost;
85 | configuration.connectionPoolMaxIdleCount = connectionPoolMaxIdleCount;
86 | configuration.connectionPoolMaxIdleMinutes = connectionPoolMaxIdleMinutes;
87 | configuration.retryMax = retryMax;
88 | return configuration;
89 | }
90 |
91 | }
92 |
--------------------------------------------------------------------------------
/docs/baidu/README.md:
--------------------------------------------------------------------------------
1 | ## 开始使用
2 |
3 | 引入以下依赖
4 |
5 | ```xml
6 |
7 | io.github.artislong
8 | oss-spring-boot-starter
9 | {latest.version}
10 |
11 |
12 | com.baidubce
13 | bce-java-sdk
14 | 0.10.196
15 |
16 | ```
17 |
18 | 通过`oss.baidu.enable=true`开启百度云OSS对象存储自动配置
19 |
20 | ## 配置详解
21 |
22 | **注:**所有具有默认值的属性,配置都可缺省,且不支持复用。
23 |
24 | - 单个百度云OSS对象存储配置
25 |
26 | ```yaml
27 | oss:
28 | baidu:
29 | enable: true
30 | access-key-id: AccessKeyId
31 | secret-access-key: SecretAccessKey
32 | bucket-name: Bucket
33 | base-path: / # 存储根路径,默认路径为 /
34 | slice-config:
35 | task-num: 8 # 并发线程数,默认等于CPU的核数
36 | part-size: 104857600 # 分片大小,单位KB,默认5MB
37 | ```
38 |
39 | 通过如上配置即可开启百度云OSS对象存储,可通过以下方式注入标准的OSS客户端。
40 |
41 | ```java
42 | @Autowired
43 | @Qualifier(BaiduOssConfiguration.DEFAULT_BEAN_NAME)
44 | private StandardOssClient ossClient;
45 | ```
46 |
47 | - 多个百度云OSS对象存储配置
48 |
49 | ```yaml
50 | oss:
51 | baidu:
52 | enable: true
53 | oss-config:
54 | baiduOssClient1:
55 | access-key-id: AccessKeyId1
56 | secret-access-key: SecretAccessKey1
57 | bucket-name: Bucket1
58 | base-path: / # 存储根路径,默认路径为 /
59 | slice-config:
60 | task-num: 8 # 并发线程数,默认等于CPU的核数
61 | part-size: 104857600 # 分片大小,单位KB,默认5MB
62 | baiduOssClient2:
63 | access-key-id: AccessKeyId2
64 | secret-access-key: SecretAccessKey2
65 | bucket-name: Bucket2
66 | base-path: / # 存储根路径,默认路径为 /
67 | slice-config:
68 | task-num: 8 # 并发线程数,默认等于CPU的核数
69 | part-size: 104857600 # 分片大小,单位KB,默认5MB
70 | ```
71 |
72 | 当配置多个百度云OSS对象存储时,使用如下方式注入
73 |
74 | ```java
75 | @Autowired
76 | @Qualifier("baiduOssClient1")
77 | private StandardOssClient baiduOssClient1;
78 | @Autowired
79 | @Qualifier("baiduOssClient2")
80 | private StandardOssClient baiduOssClient2;
81 | ```
82 |
83 | - 客户端自定义配置
84 |
85 | 可通过oss.baidu.client-config.XXX来配置,XXX具体值可通过`io.github.artislong.core.baidu.model.BaiduOssClientConfig`类查看。
86 |
87 | 
88 |
89 | 示例如下:
90 |
91 | ```yaml
92 | oss:
93 | baidu:
94 | enable: true
95 | access-key-id: AccessKeyId
96 | secret-access-key: SecretAccessKey
97 | bucket-name: Bucket
98 | base-path: / # 存储根路径,默认路径为 /
99 | client-config:
100 | connection-timeout-in-millis: 50000
101 | max-connections: 50
102 | # ......
103 | ```
104 |
105 | - 配置复用
106 |
107 | 当使用同一个百度云OSS对象存储多个不同Bucket时,可复用accessKeyId、secretAccessKey、clientConfig,只需要配置Bucket相关参数即可,示例如下:
108 |
109 | ```yaml
110 | oss:
111 | baidu:
112 | enable: true
113 | access-key-id: AccessKeyId
114 | secret-access-key: SecretAccessKey
115 | client-config:
116 | connection-timeout-in-millis: 50000
117 | max-connections: 50
118 | # ......
119 | oss-config:
120 | baiduOssClient1:
121 | bucket-name: Bucket1
122 | baiduOssClient2:
123 | bucket-name: Bucket2
124 | ```
125 |
126 |
--------------------------------------------------------------------------------
/docs/jinshan/README.md:
--------------------------------------------------------------------------------
1 | ## 开始使用
2 |
3 | 引入以下依赖
4 |
5 | ```xml
6 |
7 | io.github.artislong
8 | oss-spring-boot-starter
9 | {latest.version}
10 |
11 |
12 | com.ksyun
13 | ks3-kss-java-sdk
14 | 1.0.2
15 |
16 | ```
17 |
18 | 通过`oss.jinshan.enable=true`开启金山云OSS对象存储自动配置
19 |
20 | ## 配置详解
21 |
22 | **注:**所有具有默认值的属性,配置都可缺省,且不支持复用。
23 |
24 | - 单个金山云OSS对象存储配置
25 |
26 | ```yaml
27 | oss:
28 | jinshan:
29 | enable: true
30 | access-key-id: AccessKeyId
31 | access-key-secret: AccessKeySecret
32 | endpoint: Endpoint
33 | bucket-name: Bucket
34 | base-path: /
35 | slice-config:
36 | task-num: 8
37 | part-size: 104857600
38 | ```
39 |
40 | 通过如上配置即可开启金山云OSS对象存储,可通过以下方式注入标准的OSS客户端。
41 |
42 | ```java
43 | @Autowired
44 | @Qualifier(JinShanOssConfiguration.DEFAULT_BEAN_NAME)
45 | private StandardOssClient ossClient;
46 | ```
47 |
48 | - 多个金山云OSS对象存储配置
49 |
50 | ```yaml
51 | oss:
52 | jinshan:
53 | enable: true
54 | oss-config:
55 | jinshanOssClient1:
56 | access-key-id: AccessKeyId
57 | access-key-secret: AccessKeySecret
58 | endpoint: Endpoint
59 | bucket-name: Bucket
60 | base-path: /
61 | slice-config:
62 | task-num: 8 # 并发线程数,默认等于CPU的核数
63 | part-size: 104857600 # 分片大小,单位KB,默认5MB
64 | jinshanOssClient2:
65 | access-key-id: AccessKeyId
66 | access-key-secret: AccessKeySecret
67 | endpoint: Endpoint
68 | bucket-name: Bucket
69 | base-path: /
70 | slice-config:
71 | task-num: 8 # 并发线程数,默认等于CPU的核数
72 | part-size: 104857600 # 分片大小,单位KB,默认5MB
73 | ```
74 |
75 | 当配置多个金山云OSS对象存储时,使用如下方式注入
76 |
77 | ```java
78 | @Autowired
79 | @Qualifier("jinshanOssClient1")
80 | private StandardOssClient jinshanOssClient1;
81 | @Autowired
82 | @Qualifier("jinshanOssClient2")
83 | private StandardOssClient jinshanOssClient2;
84 | ```
85 |
86 | - 客户端自定义配置
87 |
88 | 可通过oss.jinshan.client-config.XXX来配置,XXX具体值可通过`io.github.artislong.core.jinshan.model.JinShanOssClientConfig`类查看。
89 |
90 | 
91 |
92 | 示例如下:
93 |
94 | ```yaml
95 | oss:
96 | jinshan:
97 | enable: true
98 | access-key-id: AccessKeyId
99 | access-key-secret: AccessKeySecret
100 | endpoint: Endpoint
101 | bucket-name: Bucket
102 | base-path: /
103 | client-config:
104 | connection-time-out: 50000
105 | max-connections: 50
106 | # ......
107 | ```
108 |
109 | - 配置复用
110 |
111 | 当使用同一个金山云OSS对象存储多个不同Bucket时,可复用accessKeyId、accessKeySecret、endpoint、region、clientConfig、securityToken,只需要配置Bucket相关参数即可,示例如下:
112 |
113 | ```yaml
114 | oss:
115 | jinshan:
116 | enable: true
117 | access-key-id: AccessKeyId
118 | access-key-secret: AccessKeySecret
119 | endpoint: Endpoint
120 | slice-config:
121 | task-num: 8
122 | part-size: 104857600
123 | oss-config:
124 | jinshanOssClient1:
125 | bucket-name: Bucket1
126 | jinshanOssClient2:
127 | bucket-name: Bucket2
128 | ```
129 |
130 |
--------------------------------------------------------------------------------
/docs/jd/README.md:
--------------------------------------------------------------------------------
1 | ## 开始使用
2 |
3 | 引入以下依赖
4 |
5 | ```xml
6 |
7 | io.github.artislong
8 | oss-spring-boot-starter
9 | {latest.version}
10 |
11 |
12 | com.amazonaws
13 | aws-java-sdk-s3
14 | 1.12.167
15 |
16 | ```
17 |
18 | 通过`oss.jd.enable=true`开启京东云OSS对象存储自动配置
19 |
20 | ## 配置详解
21 |
22 | **注:**所有具有默认值的属性,配置都可缺省,且不支持复用。
23 |
24 | - 单个京东云OSS对象存储配置
25 |
26 | ```yaml
27 | oss:
28 | jd:
29 | enable: true
30 | endpoint: Endpoint
31 | region: Region
32 | access-key: AccessKey
33 | secret-key: SecretKey
34 | bucket-name: Bucket
35 | base-path: /
36 | slice-config:
37 | task-num: 8
38 | part-size: 104857600
39 | ```
40 |
41 | 通过如上配置即可开启京东云OSS对象存储,可通过以下方式注入标准的OSS客户端。
42 |
43 | ```java
44 | @Autowired
45 | @Qualifier(JdOssConfiguration.DEFAULT_BEAN_NAME)
46 | private StandardOssClient ossClient;
47 | ```
48 |
49 | - 多个京东云OSS对象存储配置
50 |
51 | ```yaml
52 | oss:
53 | jd:
54 | enable: true
55 | oss-config:
56 | jdOssClient1:
57 | endpoint: Endpoint
58 | region: Region
59 | access-key: AccessKey
60 | secret-key: SecretKey
61 | bucket-name: Bucket
62 | base-path: /
63 | slice-config:
64 | task-num: 8 # 并发线程数,默认等于CPU的核数
65 | part-size: 104857600 # 分片大小,单位KB,默认5MB
66 | jdOssClient2:
67 | endpoint: Endpoint
68 | region: Region
69 | access-key: AccessKey
70 | secret-key: SecretKey
71 | bucket-name: Bucket
72 | base-path: /
73 | slice-config:
74 | task-num: 8 # 并发线程数,默认等于CPU的核数
75 | part-size: 104857600 # 分片大小,单位KB,默认5MB
76 | ```
77 |
78 | 当配置多个京东云OSS对象存储时,使用如下方式注入
79 |
80 | ```java
81 | @Autowired
82 | @Qualifier("jdOssClient1")
83 | private StandardOssClient jdOssClient1;
84 | @Autowired
85 | @Qualifier("jdOssClient2")
86 | private StandardOssClient jdOssClient2;
87 | ```
88 |
89 | - 客户端自定义配置
90 |
91 | 可通过oss.jd.client-config.XXX来配置,XXX具体值可通过`io.github.artislong.core.jd.model.JdOssClientConfig`类查看。
92 |
93 | 
94 |
95 | 示例如下:
96 |
97 | ```yaml
98 | oss:
99 | jd:
100 | enable: true
101 | endpoint: Endpoint
102 | region: Region
103 | access-key: AccessKey
104 | secret-key: SecretKey
105 | bucket-name: Bucket
106 | base-path: /
107 | client-config:
108 | connection-timeout: 50000
109 | max-connections: 50
110 | # ......
111 | ```
112 |
113 | - 配置复用
114 |
115 | 当使用同一个京东云OSS对象存储多个不同Bucket时,可复用endpoint、region、accessKey,secretKey、clientConfig,只需要配置Bucket相关参数即可,示例如下:
116 |
117 | ```yaml
118 | oss:
119 | jd:
120 | enable: true
121 | endpoint: Endpoint
122 | region: Region
123 | access-key: AccessKey
124 | secret-key: SecretKey
125 | slice-config:
126 | task-num: 8
127 | part-size: 104857600
128 | client-config:
129 | connection-timeout: 50000
130 | max-connections: 50
131 | # ......
132 | oss-config:
133 | jdOssClient1:
134 | bucket-name: Bucket1
135 | jdOssClient2:
136 | bucket-name: Bucket2
137 | ```
138 |
139 |
--------------------------------------------------------------------------------
/docs/jdbc/README.md:
--------------------------------------------------------------------------------
1 | ## 开始使用
2 |
3 | 引入以下依赖
4 |
5 | ```xml
6 |
7 | io.github.artislong
8 | oss-spring-boot-starter
9 | {latest.version}
10 |
11 |
12 | org.springframework.boot
13 | spring-boot-starter-jdbc
14 |
15 |
16 |
17 | mysql
18 | mysql-connector-java
19 |
20 |
21 | com.oracle
22 | ojdbc6
23 | 11.2.0.3
24 |
25 | ```
26 |
27 | 通过`oss.jdbc.enable=true`开启Jdbc对象存储自动配置,目前只支持Oracle、MySQL对象存储,建表脚本见jdbc目录。
28 |
29 | ## 配置详解
30 |
31 | 当系统本身不需要数据源时,记得使用`@EnableAutoConfiguration(exclude = DataSourceAutoConfiguration.class)`注解排除数据源自动配置。
32 |
33 | - 单个Jdbc对象存储配置
34 |
35 | ```yaml
36 | oss:
37 | jdbc:
38 | enable: true
39 | base-path: /
40 | type: com.zaxxer.hikari.HikariDataSource
41 | url: jdbc:mysql://127.0.0.1:3306/oss?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=UTC
42 | driver: com.mysql.cj.jdbc.Driver
43 | username: root
44 | password: root
45 | ```
46 |
47 | 通过如上配置即可开启Jdbc对象存储,可通过以下方式注入标准的OSS客户端。
48 |
49 | ```java
50 | @Autowired
51 | @Qualifier(JdbcOssConfiguration.DEFAULT_BEAN_NAME)
52 | private StandardOssClient ossClient;
53 | ```
54 |
55 | - 多个Jdbc对象存储配置
56 |
57 | ```yaml
58 | oss:
59 | jdbc:
60 | enable: true
61 | oss-config:
62 | mysqlOssClient:
63 | base-path: /
64 | type: com.zaxxer.hikari.HikariDataSource
65 | url: jdbc:mysql://127.0.0.1:3306/oss?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=UTC
66 | driver: com.mysql.cj.jdbc.Driver
67 | username: root
68 | password: root
69 | oracleOssClient:
70 | base-path: /
71 | type: com.zaxxer.hikari.HikariDataSource
72 | url: jdbc:oracle:thin:@127.0.0.1:1521:orcl
73 | driver: oracle.jdbc.driver.OracleDriver
74 | username: oss
75 | password: oss123
76 | ```
77 |
78 | 当配置多个Jdbc对象存储时,使用如下方式注入
79 |
80 | ```java
81 | @Autowired
82 | @Qualifier("mysqlOssClient")
83 | private StandardOssClient mysqlOssClient;
84 | @Autowired
85 | @Qualifier("oracleOssClient")
86 | private StandardOssClient oracleOssClient;
87 | ```
88 |
89 | - 使用系统默认数据源
90 |
91 | 当系统本身已经配置了数据源,此时不需要单独配置对象存储数据源,对象存储将采用系统默认数据源
92 |
93 | ```yaml
94 | oss:
95 | jdbc:
96 | enable: true
97 | base-path: /
98 | ```
99 |
100 | - 系统存在多个数据源Bean
101 |
102 | 注意:是多个数据源Bean对象,不是通过`AbstractDataSource`实现的多数据源配置
103 |
104 | ```yaml
105 | oss:
106 | jdbc:
107 | enable: true
108 | base-path: /
109 | data-source-name: 数据源Bean名称
110 | ```
111 |
112 | - 系统存在多个数据源Bean,配置多个Jdbc对象存储时
113 |
114 | 在系统配置了多个数据源Bean对象,且需要在多个数据源中使用对象存储,可通过**多个Jdbc对象存储配置**时配置数据源Bean名称来实现
115 |
116 | ```yaml
117 | oss:
118 | jdbc:
119 | enable: true
120 | oss-config:
121 | mysqlOssClient:
122 | base-path: /
123 | data-source-name: 数据源Bean名称
124 | oracleOssClient:
125 | base-path: /
126 | data-source-name: 数据源Bean名称
127 | ```
128 |
129 |
--------------------------------------------------------------------------------
/docs/tencent/README.md:
--------------------------------------------------------------------------------
1 | ## 开始使用
2 |
3 | 引入以下依赖
4 |
5 | ```xml
6 |
7 | io.github.artislong
8 | oss-spring-boot-starter
9 | {latest.version}
10 |
11 |
12 | com.qcloud
13 | cos_api
14 | 5.6.69
15 |
16 | ```
17 |
18 | 通过`oss.tencent.enable=true`开启腾讯云OSS对象存储自动配置
19 |
20 | ## 配置详解
21 |
22 | **注:**所有具有默认值的属性,配置都可缺省,且不支持复用。
23 |
24 | - 单个腾讯云OSS对象存储配置
25 |
26 | ```yaml
27 | oss:
28 | tencent:
29 | enable: true
30 | secret-key: SecretKey
31 | secret-id: SecretId
32 | bucket-name: Bucket
33 | base-path: /
34 | slice-config:
35 | task-num: 8
36 | part-size: 104857600
37 | client-config:
38 | region: cos.ap-chengdu
39 | ```
40 |
41 | 通过如上配置即可开启腾讯云OSS对象存储,可通过以下方式注入标准的OSS客户端。
42 |
43 | ```java
44 | @Autowired
45 | @Qualifier(TencentOssConfiguration.DEFAULT_BEAN_NAME)
46 | private StandardOssClient ossClient;
47 | ```
48 |
49 | - 多个腾讯云OSS对象存储配置
50 |
51 | ```yaml
52 | oss:
53 | tencent:
54 | enable: true
55 | oss-config:
56 | tencentOssClient1:
57 | secret-key: SecretKey1
58 | secret-id: SecretId1
59 | bucket-name: Bucket1
60 | base-path: / # 存储根路径,默认路径为 /
61 | slice-config:
62 | task-num: 8 # 并发线程数,默认等于CPU的核数
63 | part-size: 104857600 # 分片大小,单位KB,默认5MB
64 | client-config:
65 | region: cos.ap-chengdu
66 | tencentOssClient2:
67 | secret-key: SecretKey1
68 | secret-id: SecretId1
69 | bucket-name: Bucket2
70 | base-path: / # 存储根路径,默认路径为 /
71 | slice-config:
72 | task-num: 8 # 并发线程数,默认等于CPU的核数
73 | part-size: 104857600 # 分片大小,单位KB,默认5MB
74 | client-config:
75 | region: cos.ap-chengdu
76 | ```
77 |
78 | 当配置多个腾讯云OSS对象存储时,使用如下方式注入
79 |
80 | ```java
81 | @Autowired
82 | @Qualifier("tencentOssClient1")
83 | private StandardOssClient tencentOssClient1;
84 | @Autowired
85 | @Qualifier("tencentOssClient2")
86 | private StandardOssClient tencentOssClient2;
87 | ```
88 |
89 | - 客户端自定义配置
90 |
91 | 可通过oss.tencent.client-config.XXX来配置,XXX具体值可通过`io.github.artislong.core.tencent.model.TencentOssClientConfig`类查看。
92 |
93 | 
94 |
95 | 示例如下:
96 |
97 | ```yaml
98 | oss:
99 | tencent:
100 | enable: true
101 | secret-key: SecretKey
102 | secret-id: SecretId
103 | bucket-name: Bucket
104 | base-path: / # 存储根路径,默认路径为 /
105 | client-config:
106 | region: cos.ap-chengdu
107 | connection-timeout: 50000
108 | max-connections-count: 50
109 | # ......
110 | ```
111 |
112 | - 配置复用
113 |
114 | 当使用同一个腾讯云OSS对象存储多个不同Bucket时,可复用secretKey、secretId、clientConfig,只需要配置Bucket相关参数即可,示例如下:
115 |
116 | ```yaml
117 | oss:
118 | tencent:
119 | enable: true
120 | secret-key: SecretKey
121 | secret-id: SecretId
122 | client-config:
123 | region: cos.ap-chengdu
124 | connection-timeout: 50000
125 | max-connections-count: 50
126 | # ......
127 | oss-config:
128 | tencentOssClient1:
129 | bucket-name: Bucket1
130 | tencentOssClient2:
131 | bucket-name: Bucket2
132 | ```
133 |
134 |
--------------------------------------------------------------------------------
/docs/ucloud/README.md:
--------------------------------------------------------------------------------
1 | 暂无测试环境,待测试
2 |
3 | ## 开始使用
4 |
5 | 引入以下依赖
6 |
7 | ```xml
8 |
9 | io.github.artislong
10 | oss-spring-boot-starter
11 | {latest.version}
12 |
13 |
14 | cn.ucloud.ufile
15 | ufile-client-java
16 | 2.6.6
17 |
18 | ```
19 |
20 | 通过`oss.ucloud.enable=true`开启Ucloud OSS对象存储自动配置
21 |
22 | ## 配置详解
23 |
24 | **注:**所有具有默认值的属性,配置都可缺省,且不支持复用。
25 |
26 | - 单个Ucloud OSS对象存储配置
27 |
28 | ```yaml
29 | oss:
30 | ucloud:
31 | enable: true
32 | public-key: PublicKey
33 | private-key: PrivateKey
34 | custom-host: CustomHost
35 | bucket-name: Bucket
36 | base-path: /
37 | slice-config:
38 | task-num: 8
39 | part-size: 104857600
40 | ```
41 |
42 | 通过如上配置即可开启Ucloud OSS对象存储,可通过以下方式注入标准的OSS客户端。
43 |
44 | ```java
45 | @Autowired
46 | @Qualifier(UcloudOssConfiguration.DEFAULT_BEAN_NAME)
47 | private StandardOssClient ossClient;
48 | ```
49 |
50 | - 多个Ucloud OSS对象存储配置
51 |
52 | ```yaml
53 | oss:
54 | ucloud:
55 | enable: true
56 | oss-config:
57 | ucloudOssClient1:
58 | public-key: PublicKey
59 | private-key: PrivateKey
60 | custom-host: CustomHost
61 | bucket-name: Bucket1
62 | base-path: / # 存储根路径,默认路径为 /
63 | slice-config:
64 | task-num: 8 # 并发线程数,默认等于CPU的核数
65 | part-size: 104857600 # 分片大小,单位KB,默认5MB
66 | ucloudOssClient2:
67 | public-key: PublicKey
68 | private-key: PrivateKey
69 | custom-host: CustomHost
70 | bucket-name: Bucket2
71 | base-path: / # 存储根路径,默认路径为 /
72 | slice-config:
73 | task-num: 8 # 并发线程数,默认等于CPU的核数
74 | part-size: 104857600 # 分片大小,单位KB,默认5MB
75 | ```
76 |
77 | 当配置多个Ucloud OSS对象存储时,使用如下方式注入
78 |
79 | ```java
80 | @Autowired
81 | @Qualifier("ucloudOssClient1")
82 | private StandardOssClient ucloudOssClient1;
83 | @Autowired
84 | @Qualifier("ucloudOssClient2")
85 | private StandardOssClient ucloudOssClient2;
86 | ```
87 |
88 | - 客户端自定义配置
89 |
90 | 可通过oss.ucloud.client-config.XXX来配置,XXX具体值可通过`io.github.artislong.core.ucloud.model.UcloudOssClientConfig`类查看。
91 |
92 | 
93 |
94 | 示例如下:
95 |
96 | ```yaml
97 | oss:
98 | ucloud:
99 | enable: true
100 | public-key: PublicKey
101 | private-key: PrivateKey
102 | custom-host: CustomHost
103 | bucket-name: Bucket
104 | base-path: / # 存储根路径,默认路径为 /
105 | client-config:
106 | timeout-connect: 50000
107 | timeout-read: 50000
108 | # ......
109 | ```
110 |
111 | - 配置复用
112 |
113 | 当使用同一个Ucloud OSS对象存储多个不同Bucket时,可复用publicKey、privateKey、customHost、clientConfig,只需要配置Bucket相关参数即可,示例如下:
114 |
115 | ```yaml
116 | oss:
117 | ucloud:
118 | enable: true
119 | public-key: PublicKey
120 | private-key: PrivateKey
121 | custom-host: CustomHost
122 | client-config:
123 | timeout-connect: 50000
124 | timeout-read: 50000
125 | # ......
126 | oss-config:
127 | ucloudOssClient1:
128 | bucket-name: Bucket1
129 | ucloudOssClient2:
130 | bucket-name: Bucket2
131 | ```
132 |
133 |
--------------------------------------------------------------------------------
/docs/wangyi/README.md:
--------------------------------------------------------------------------------
1 | 暂无测试环境,待测试
2 |
3 | ## 开始使用
4 |
5 | 引入以下依赖
6 |
7 | ```xml
8 |
9 | io.github.artislong
10 | oss-spring-boot-starter
11 | {latest.version}
12 |
13 |
14 | com.netease.cloud
15 | nos-sdk-java-publiccloud
16 | 1.3.1
17 |
18 | ```
19 |
20 | 通过`oss.wangyi.enable=true`开启网易数帆OSS对象存储自动配置
21 |
22 | ## 配置详解
23 |
24 | **注:**所有具有默认值的属性,配置都可缺省,且不支持复用。
25 |
26 | - 单个网易数帆OSS对象存储配置
27 |
28 | ```yaml
29 | oss:
30 | wangyi:
31 | enable: true
32 | endpoint: Endpoint
33 | access-key: AccessKey
34 | secret-key: SecretKey
35 | bucket-name: Bucket
36 | base-path: /
37 | slice-config:
38 | task-num: 8
39 | part-size: 104857600
40 | ```
41 |
42 | 通过如上配置即可开启网易数帆OSS对象存储,可通过以下方式注入标准的OSS客户端。
43 |
44 | ```java
45 | @Autowired
46 | @Qualifier(WangYiOssConfiguration.DEFAULT_BEAN_NAME)
47 | private StandardOssClient ossClient;
48 | ```
49 |
50 | - 多个网易数帆OSS对象存储配置
51 |
52 | ```yaml
53 | oss:
54 | wangyi:
55 | enable: true
56 | oss-config:
57 | wangyiOssClient1:
58 | endpoint: Endpoint
59 | access-key: AccessKey
60 | secret-key: SecretKey
61 | bucket-name: Bucket1
62 | base-path: / # 存储根路径,默认路径为 /
63 | slice-config:
64 | task-num: 8 # 并发线程数,默认等于CPU的核数
65 | part-size: 104857600 # 分片大小,单位KB,默认5MB
66 | client-config:
67 | region: cos.ap-chengdu
68 | wangyiOssClient2:
69 | endpoint: Endpoint
70 | access-key: AccessKey
71 | secret-key: SecretKey
72 | bucket-name: Bucket2
73 | base-path: / # 存储根路径,默认路径为 /
74 | slice-config:
75 | task-num: 8 # 并发线程数,默认等于CPU的核数
76 | part-size: 104857600 # 分片大小,单位KB,默认5MB
77 | ```
78 |
79 | 当配置多个网易数帆OSS对象存储时,使用如下方式注入
80 |
81 | ```java
82 | @Autowired
83 | @Qualifier("wangyiOssClient1")
84 | private StandardOssClient wangyiOssClient1;
85 | @Autowired
86 | @Qualifier("wangyiOssClient2")
87 | private StandardOssClient wangyiOssClient2;
88 | ```
89 |
90 | - 客户端自定义配置
91 |
92 | 可通过oss.wangyi.client-config.XXX来配置,XXX具体值可通过`io.github.artislong.core.wangyi.model.WangYiOssClientConfig`类查看。
93 |
94 | 
95 |
96 | 示例如下:
97 |
98 | ```yaml
99 | oss:
100 | wangyi:
101 | enable: true
102 | endpoint: Endpoint
103 | access-key: AccessKey
104 | secret-key: SecretKey
105 | bucket-name: Bucket
106 | base-path: / # 存储根路径,默认路径为 /
107 | client-config:
108 | connection-timeout: 50000
109 | max-connections: 50
110 | # ......
111 | ```
112 |
113 | - 配置复用
114 |
115 | 当使用同一个网易数帆OSS对象存储多个不同Bucket时,可复用endpoint、secretKey、accessKey、clientConfig,只需要配置Bucket相关参数即可,示例如下:
116 |
117 | ```yaml
118 | oss:
119 | wangyi:
120 | enable: true
121 | endpoint: Endpoint
122 | access-key: AccessKey
123 | secret-key: SecretKey
124 | client-config:
125 | connection-timeout: 50000
126 | max-connections: 50
127 | # ......
128 | oss-config:
129 | wangyiOssClient1:
130 | bucket-name: Bucket1
131 | wangyiOssClient2:
132 | bucket-name: Bucket2
133 | ```
134 |
135 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/wangyi/WangYiOssConfiguration.java:
--------------------------------------------------------------------------------
1 | /**
* $Id: WangYiOssConfiguration.java,v 1.0 2022/3/4 9:49 PM chenmin Exp $
*/
package io.github.artislong.core.wangyi;
import cn.hutool.core.text.CharPool;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.netease.cloud.auth.BasicCredentials;
import com.netease.cloud.auth.Credentials;
import com.netease.cloud.services.nos.NosClient;
import io.github.artislong.constant.OssConstant;
import io.github.artislong.core.StandardOssClient;
import io.github.artislong.core.wangyi.model.WangYiOssClientConfig;
import io.github.artislong.core.wangyi.model.WangYiOssConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import java.util.Map;
/**
* @author 陈敏
* @version $Id: WangYiOssConfiguration.java,v 1.1 2022/3/4 9:49 PM chenmin Exp $
* Created on 2022/3/4 9:49 PM
* My blog: https://www.chenmin.info
*/
@SpringBootConfiguration
@ConditionalOnClass(NosClient.class)
@EnableConfigurationProperties({WangYiOssProperties.class})
@ConditionalOnProperty(prefix = OssConstant.OSS, name = OssConstant.OssType.WANGYI + CharPool.DOT + OssConstant.ENABLE,
havingValue = OssConstant.DEFAULT_ENABLE_VALUE)
public class WangYiOssConfiguration {
public static final String DEFAULT_BEAN_NAME = "wangYiOssClient";
@Autowired
private WangYiOssProperties wangYiOssProperties;
@Bean
public StandardOssClient wangYiOssClient() {
Map wangYiOssConfigMap = wangYiOssProperties.getOssConfig();
if (wangYiOssConfigMap.isEmpty()) {
SpringUtil.registerBean(DEFAULT_BEAN_NAME, wangYiOssClient(wangYiOssProperties));
} else {
String endPoint = wangYiOssProperties.getEndpoint();
String accessKey = wangYiOssProperties.getAccessKey();
String secretKey = wangYiOssProperties.getSecretKey();
WangYiOssClientConfig clientConfig = wangYiOssProperties.getClientConfig();
wangYiOssConfigMap.forEach((name, wangYiOssConfig) -> {
if (ObjectUtil.isEmpty(wangYiOssConfig.getEndpoint())) {
wangYiOssConfig.setEndpoint(endPoint);
}
if (ObjectUtil.isEmpty(wangYiOssConfig.getAccessKey())) {
wangYiOssConfig.setAccessKey(accessKey);
}
if (ObjectUtil.isEmpty(wangYiOssConfig.getSecretKey())) {
wangYiOssConfig.setSecretKey(secretKey);
}
if (ObjectUtil.isEmpty(wangYiOssConfig.getClientConfig())) {
wangYiOssConfig.setClientConfig(clientConfig);
}
SpringUtil.registerBean(name, wangYiOssClient(wangYiOssConfig));
});
}
return null;
}
public StandardOssClient wangYiOssClient(WangYiOssConfig ossConfig) {
return new WangYiOssClient(nosClient(ossConfig), ossConfig);
}
public NosClient nosClient(WangYiOssConfig ossConfig) {
Credentials credentials = new BasicCredentials(ossConfig.getAccessKey(), ossConfig.getSecretKey());
NosClient nosClient = new NosClient(credentials);
nosClient.setEndpoint(ossConfig.getEndpoint());
nosClient.setConfiguration(ossConfig.getClientConfig().toClientConfig());
return nosClient;
}
}
--------------------------------------------------------------------------------
/docs/minio/README.md:
--------------------------------------------------------------------------------
1 | ## 开始使用
2 |
3 | 引入以下依赖
4 |
5 | ```xml
6 |
7 | io.github.artislong
8 | oss-spring-boot-starter
9 | {latest.version}
10 |
11 |
12 | io.minio
13 | minio
14 | 8.3.5
15 |
16 |
17 |
18 | com.squareup.okhttp3
19 | okhttp
20 | 4.9.3
21 |
22 | ```
23 |
24 | 通过`oss.minio.enable=true`开启Minio OSS对象存储自动配置
25 |
26 | ## 配置详解
27 |
28 | **注:**所有具有默认值的属性,配置都可缺省,且不支持复用。
29 |
30 | - 单个Minio OSS对象存储配置
31 |
32 | ```yaml
33 | oss:
34 | minio:
35 | enable: true
36 | endpoint: https://play.min.io
37 | access-key: Q3AM3UQ867SPQQA43P2F
38 | secret-key: zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG
39 | bucket-name: Bucket
40 | base-path: /
41 | slice-config:
42 | task-num: 8
43 | part-size: 104857600
44 | ```
45 |
46 | 通过如上配置即可开启Minio OSS对象存储,可通过以下方式注入标准的OSS客户端。
47 |
48 | ```java
49 | @Autowired
50 | @Qualifier(MinioOssConfiguration.DEFAULT_BEAN_NAME)
51 | private StandardOssClient ossClient;
52 | ```
53 |
54 | - 多个Minio OSS对象存储配置
55 |
56 | ```yaml
57 | oss:
58 | minio:
59 | enable: true
60 | oss-config:
61 | minioOssClient1:
62 | endpoint: https://play.min.io
63 | access-key: Q3AM3UQ867SPQQA43P2F
64 | secret-key: zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG
65 | bucket-name: Bucket1
66 | base-path: /
67 | slice-config:
68 | task-num: 8
69 | part-size: 104857600
70 | minioOssClient2:
71 | endpoint: https://play.min.io
72 | access-key: Q3AM3UQ867SPQQA43P2F
73 | secret-key: zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG
74 | bucket-name: Bucket2
75 | base-path: /
76 | slice-config:
77 | task-num: 8
78 | part-size: 104857600
79 | ```
80 |
81 | 当配置多个Minio OSS对象存储时,使用如下方式注入
82 |
83 | ```java
84 | @Autowired
85 | @Qualifier("minioOssClient1")
86 | private StandardOssClient minioOssClient1;
87 | @Autowired
88 | @Qualifier("minioOssClient2")
89 | private StandardOssClient minioOssClient2;
90 | ```
91 |
92 | - 客户端自定义配置
93 |
94 | 可通过oss.minio.client-config.XXX来配置,XXX具体值可通过`io.github.artislong.core.minio.model.MinioOssClientConfig`类查看。
95 |
96 | 
97 |
98 | 示例如下:
99 |
100 | ```yaml
101 | oss:
102 | minio:
103 | enable: true
104 | endpoint: https://play.min.io
105 | access-key: Q3AM3UQ867SPQQA43P2F
106 | secret-key: zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG
107 | bucket-name: Bucket
108 | base-path: /
109 | slice-config:
110 | task-num: 8
111 | part-size: 104857600
112 | client-config:
113 | connect-timeout: 5
114 | write-timeout: 5
115 | read-timeout: 5
116 | # ......
117 | ```
118 |
119 | - 配置复用
120 |
121 | 当使用同一个Minio OSS对象存储多个不同Bucket时,可复用endpoint、accessKey、secretKey,只需要配置Bucket相关参数即可,示例如下:
122 |
123 | ```yaml
124 | oss:
125 | minio:
126 | enable: true
127 | endpoint: https://play.min.io
128 | access-key: Q3AM3UQ867SPQQA43P2F
129 | secret-key: zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG
130 | slice-config:
131 | task-num: 8
132 | part-size: 104857600
133 | oss-config:
134 | minioOssClient1:
135 | bucket-name: Bucket1
136 | minioOssClient2:
137 | bucket-name: Bucket2
138 | ```
139 |
140 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/huawei/HuaWeiOssConfiguration.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.huawei;
2 |
3 | import cn.hutool.core.text.CharPool;
4 | import cn.hutool.core.util.ObjectUtil;
5 | import cn.hutool.extra.spring.SpringUtil;
6 | import com.obs.services.ObsClient;
7 | import com.obs.services.ObsConfiguration;
8 | import io.github.artislong.constant.OssConstant;
9 | import io.github.artislong.core.StandardOssClient;
10 | import io.github.artislong.core.huawei.model.HuaweiOssClientConfig;
11 | import io.github.artislong.core.huawei.model.HuaweiOssConfig;
12 | import org.springframework.beans.factory.annotation.Autowired;
13 | import org.springframework.boot.SpringBootConfiguration;
14 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
15 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
16 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
17 | import org.springframework.context.annotation.Bean;
18 |
19 | import java.util.Map;
20 | import java.util.Optional;
21 |
22 | /**
23 | * @author 陈敏
24 | * @version HuaWeiOssConfiguration.java, v 1.1 2021/11/25 9:58 chenmin Exp $
25 | * Created on 2021/11/25
26 | */
27 | @SpringBootConfiguration
28 | @ConditionalOnClass(ObsClient.class)
29 | @EnableConfigurationProperties({HuaWeiOssProperties.class})
30 | @ConditionalOnProperty(prefix = OssConstant.OSS, name = OssConstant.OssType.HUAWEI + CharPool.DOT + OssConstant.ENABLE,
31 | havingValue = OssConstant.DEFAULT_ENABLE_VALUE)
32 | public class HuaWeiOssConfiguration {
33 |
34 | public static final String DEFAULT_BEAN_NAME = "huaWeiOssClient";
35 |
36 | @Autowired
37 | private HuaWeiOssProperties huaWeiOssProperties;
38 |
39 | @Bean
40 | public StandardOssClient huaWeiOssClient() {
41 | Map huaweiOssConfigMap = huaWeiOssProperties.getOssConfig();
42 | if (huaweiOssConfigMap.isEmpty()) {
43 | SpringUtil.registerBean(DEFAULT_BEAN_NAME, huaWeiOssClient(huaWeiOssProperties));
44 | } else {
45 | String accessKey = huaWeiOssProperties.getAccessKey();
46 | String secretKey = huaWeiOssProperties.getSecretKey();
47 | String endPoint = huaWeiOssProperties.getEndPoint();
48 | HuaweiOssClientConfig clientConfig = huaWeiOssProperties.getClientConfig();
49 | huaweiOssConfigMap.forEach((name, huaweiOssConfig) -> {
50 | if (ObjectUtil.isEmpty(huaweiOssConfig.getAccessKey())) {
51 | huaweiOssConfig.setAccessKey(accessKey);
52 | }
53 | if (ObjectUtil.isEmpty(huaweiOssConfig.getSecretKey())) {
54 | huaweiOssConfig.setSecretKey(secretKey);
55 | }
56 | if (ObjectUtil.isEmpty(huaweiOssConfig.getClientConfig())) {
57 | huaweiOssConfig.setClientConfig(clientConfig);
58 | }
59 | if (ObjectUtil.isEmpty(huaweiOssConfig.getEndPoint())) {
60 | huaweiOssConfig.setEndPoint(endPoint);
61 | }
62 | SpringUtil.registerBean(name, huaWeiOssClient(huaweiOssConfig));
63 | });
64 | }
65 | return null;
66 | }
67 |
68 | public StandardOssClient huaWeiOssClient(HuaweiOssConfig huaweiOssConfig) {
69 | return new HuaWeiOssClient(obsClient(huaweiOssConfig), huaweiOssConfig);
70 | }
71 |
72 | public ObsClient obsClient(HuaweiOssConfig huaweiOssConfig) {
73 | HuaweiOssClientConfig clientConfig = Optional.ofNullable(huaweiOssConfig.getClientConfig()).orElse(new HuaweiOssClientConfig());
74 | ObsConfiguration obsConfiguration = clientConfig.toClientConfig();
75 | obsConfiguration.setEndPoint(huaweiOssConfig.getEndPoint());
76 | return new ObsClient(huaweiOssConfig.getAccessKey(), huaweiOssConfig.getSecretKey(), obsConfiguration);
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/baidu/BaiduOssConfiguration.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.baidu;
2 |
3 | import cn.hutool.core.text.CharPool;
4 | import cn.hutool.core.util.ObjectUtil;
5 | import cn.hutool.extra.spring.SpringUtil;
6 | import com.baidubce.auth.DefaultBceCredentials;
7 | import com.baidubce.services.bos.BosClient;
8 | import com.baidubce.services.bos.BosClientConfiguration;
9 | import io.github.artislong.constant.OssConstant;
10 | import io.github.artislong.core.StandardOssClient;
11 | import io.github.artislong.core.baidu.model.BaiduOssClientConfig;
12 | import io.github.artislong.core.baidu.model.BaiduOssConfig;
13 | import org.springframework.beans.factory.annotation.Autowired;
14 | import org.springframework.boot.SpringBootConfiguration;
15 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
16 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
17 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
18 | import org.springframework.context.annotation.Bean;
19 |
20 | import java.util.Map;
21 | import java.util.Optional;
22 |
23 | /**
24 | * @author 陈敏
25 | * @version BaiduConfiguration.java, v 1.1 2021/11/24 15:26 chenmin Exp $
26 | * Created on 2021/11/24
27 | */
28 | @SpringBootConfiguration
29 | @ConditionalOnClass(BosClient.class)
30 | @EnableConfigurationProperties({BaiduOssProperties.class})
31 | @ConditionalOnProperty(prefix = OssConstant.OSS, name = OssConstant.OssType.BAIDU + CharPool.DOT + OssConstant.ENABLE,
32 | havingValue = OssConstant.DEFAULT_ENABLE_VALUE)
33 | public class BaiduOssConfiguration {
34 |
35 | public static final String DEFAULT_BEAN_NAME = "baiduOssClient";
36 |
37 | @Autowired
38 | private BaiduOssProperties baiduOssProperties;
39 |
40 | @Bean
41 | public StandardOssClient baiduOssClient() {
42 | Map baiduOssConfigMap = baiduOssProperties.getOssConfig();
43 | if (baiduOssConfigMap.isEmpty()) {
44 | SpringUtil.registerBean(DEFAULT_BEAN_NAME, baiduOssClient(baiduOssProperties));
45 | } else {
46 | String accessKeyId = baiduOssProperties.getAccessKeyId();
47 | String secretAccessKey = baiduOssProperties.getSecretAccessKey();
48 | BaiduOssClientConfig clientConfig = baiduOssProperties.getClientConfig();
49 | baiduOssConfigMap.forEach((name, baiduOssConfig) -> {
50 | if (ObjectUtil.isEmpty(baiduOssConfig.getAccessKeyId())) {
51 | baiduOssConfig.setAccessKeyId(accessKeyId);
52 | }
53 | if (ObjectUtil.isEmpty(baiduOssConfig.getSecretAccessKey())) {
54 | baiduOssConfig.setSecretAccessKey(secretAccessKey);
55 | }
56 | if (ObjectUtil.isEmpty(baiduOssConfig.getClientConfig())) {
57 | baiduOssConfig.setClientConfig(clientConfig);
58 | }
59 | SpringUtil.registerBean(name, baiduOssClient(baiduOssConfig));
60 | });
61 | }
62 | return null;
63 | }
64 |
65 | public StandardOssClient baiduOssClient(BaiduOssConfig baiduOssConfig) {
66 | return new BaiduOssClient(bosClient(bosClientConfiguration(baiduOssConfig)), baiduOssConfig);
67 | }
68 |
69 | public BosClientConfiguration bosClientConfiguration(BaiduOssConfig baiduOssConfig) {
70 | BaiduOssClientConfig clientConfig = Optional.ofNullable(baiduOssConfig.getClientConfig()).orElse(new BaiduOssClientConfig());
71 | BosClientConfiguration bosClientConfiguration = clientConfig.toClientConfig();
72 | bosClientConfiguration.setCredentials(new DefaultBceCredentials(baiduOssConfig.getAccessKeyId(), baiduOssConfig.getSecretAccessKey()));
73 | return bosClientConfiguration;
74 | }
75 |
76 | public BosClient bosClient(BosClientConfiguration config) {
77 | return new BosClient(config);
78 | }
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/tencent/TencentOssConfiguration.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.tencent;
2 |
3 | import cn.hutool.core.text.CharPool;
4 | import cn.hutool.core.util.ObjectUtil;
5 | import cn.hutool.extra.spring.SpringUtil;
6 | import com.qcloud.cos.COSClient;
7 | import com.qcloud.cos.ClientConfig;
8 | import com.qcloud.cos.auth.BasicCOSCredentials;
9 | import com.qcloud.cos.auth.COSCredentials;
10 | import io.github.artislong.constant.OssConstant;
11 | import io.github.artislong.core.StandardOssClient;
12 | import io.github.artislong.core.tencent.model.TencentOssClientConfig;
13 | import io.github.artislong.core.tencent.model.TencentOssConfig;
14 | import org.springframework.beans.factory.annotation.Autowired;
15 | import org.springframework.boot.SpringBootConfiguration;
16 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
17 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
18 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
19 | import org.springframework.context.annotation.Bean;
20 |
21 | import java.util.Map;
22 | import java.util.Optional;
23 |
24 | /**
25 | * @author 陈敏
26 | * @version TencentConfiguration.java, v 1.1 2021/11/24 15:22 chenmin Exp $
27 | * Created on 2021/11/24
28 | */
29 | @SpringBootConfiguration
30 | @ConditionalOnClass(COSClient.class)
31 | @EnableConfigurationProperties({TencentOssProperties.class})
32 | @ConditionalOnProperty(prefix = OssConstant.OSS, name = OssConstant.OssType.TENCENT + CharPool.DOT + OssConstant.ENABLE,
33 | havingValue = OssConstant.DEFAULT_ENABLE_VALUE)
34 | public class TencentOssConfiguration {
35 |
36 | public static final String DEFAULT_BEAN_NAME = "tencentOssClient";
37 |
38 | @Autowired
39 | private TencentOssProperties tencentOssProperties;
40 |
41 | @Bean
42 | public StandardOssClient tencentOssClient() {
43 | Map tencentOssConfigMap = tencentOssProperties.getOssConfig();
44 | if (tencentOssConfigMap.isEmpty()) {
45 | SpringUtil.registerBean(DEFAULT_BEAN_NAME, tencentOssClient(tencentOssProperties));
46 | } else {
47 | String secretId = tencentOssProperties.getSecretId();
48 | String secretKey = tencentOssProperties.getSecretKey();
49 | TencentOssClientConfig clientConfig = tencentOssProperties.getClientConfig();
50 | tencentOssConfigMap.forEach((name, tencentOssConfig) -> {
51 | if (ObjectUtil.isEmpty(tencentOssConfig.getSecretId())) {
52 | tencentOssConfig.setSecretId(secretId);
53 | }
54 | if (ObjectUtil.isEmpty(tencentOssConfig.getSecretKey())) {
55 | tencentOssConfig.setSecretKey(secretKey);
56 | }
57 | if (ObjectUtil.isEmpty(tencentOssConfig.getClientConfig())) {
58 | tencentOssConfig.setClientConfig(clientConfig);
59 | }
60 | SpringUtil.registerBean(name, tencentOssClient(tencentOssConfig));
61 | });
62 | }
63 | return null;
64 | }
65 |
66 | private StandardOssClient tencentOssClient(TencentOssConfig tencentOssConfig) {
67 | TencentOssClientConfig clientConfig = Optional.ofNullable(tencentOssConfig.getClientConfig()).orElse(new TencentOssClientConfig());
68 | COSCredentials cosCredentials = cosCredentials(tencentOssConfig);
69 | COSClient cosClient = cosClient(cosCredentials, clientConfig.toClientConfig());
70 | return tencentOssClient(cosClient, tencentOssConfig);
71 | }
72 |
73 | public StandardOssClient tencentOssClient(COSClient cosClient, TencentOssConfig tencentOssConfig) {
74 | return new TencentOssClient(cosClient, tencentOssConfig);
75 | }
76 |
77 | public COSCredentials cosCredentials(TencentOssConfig tencentOssConfig) {
78 | return new BasicCOSCredentials(tencentOssConfig.getSecretId(), tencentOssConfig.getSecretKey());
79 | }
80 |
81 | public COSClient cosClient(COSCredentials cred, ClientConfig clientConfig) {
82 | return new COSClient(cred, clientConfig);
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/ucloud/UCloudOssConfiguration.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.ucloud;
2 |
3 | import cn.hutool.core.text.CharPool;
4 | import cn.hutool.core.util.ObjectUtil;
5 | import cn.hutool.extra.spring.SpringUtil;
6 | import cn.ucloud.ufile.UfileClient;
7 | import cn.ucloud.ufile.api.object.ObjectApiBuilder;
8 | import cn.ucloud.ufile.api.object.ObjectConfig;
9 | import cn.ucloud.ufile.auth.ObjectAuthorization;
10 | import cn.ucloud.ufile.auth.UfileObjectLocalAuthorization;
11 | import io.github.artislong.constant.OssConstant;
12 | import io.github.artislong.core.StandardOssClient;
13 | import io.github.artislong.core.ucloud.model.UCloudOssClientConfig;
14 | import io.github.artislong.core.ucloud.model.UCloudOssConfig;
15 | import org.springframework.beans.factory.annotation.Autowired;
16 | import org.springframework.boot.SpringBootConfiguration;
17 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
18 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
19 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
20 | import org.springframework.context.annotation.Bean;
21 |
22 | import java.util.Map;
23 | import java.util.Optional;
24 |
25 | /**
26 | * @author 陈敏
27 | * @version UCloudOssConfiguration.java, v 1.1 2022/3/7 0:20 chenmin Exp $
28 | * Created on 2022/3/7
29 | */
30 | @SpringBootConfiguration
31 | @ConditionalOnClass(UfileClient.class)
32 | @EnableConfigurationProperties({UCloudOssProperties.class})
33 | @ConditionalOnProperty(prefix = OssConstant.OSS, name = OssConstant.OssType.UCLOUD + CharPool.DOT + OssConstant.ENABLE,
34 | havingValue = OssConstant.DEFAULT_ENABLE_VALUE)
35 | public class UCloudOssConfiguration {
36 |
37 | public static final String DEFAULT_BEAN_NAME = "uCloudOssClient";
38 |
39 | @Autowired
40 | private UCloudOssProperties uCloudOssProperties;
41 |
42 | @Bean
43 | public StandardOssClient uCloudOssClient() {
44 | Map ossConfigMap = uCloudOssProperties.getOssConfig();
45 | if (ossConfigMap.isEmpty()) {
46 | SpringUtil.registerBean(DEFAULT_BEAN_NAME, uCloudOssClient(uCloudOssProperties));
47 | } else {
48 | String publicKey = uCloudOssProperties.getPublicKey();
49 | String privateKey = uCloudOssProperties.getPrivateKey();
50 | String customHost = uCloudOssProperties.getCustomHost();
51 | UCloudOssClientConfig clientConfig = uCloudOssProperties.getClientConfig();
52 | ossConfigMap.forEach((name, ossConfig) -> {
53 | if (ObjectUtil.isEmpty(ossConfig.getPublicKey())) {
54 | ossConfig.setPublicKey(publicKey);
55 | }
56 | if (ObjectUtil.isEmpty(ossConfig.getPrivateKey())) {
57 | ossConfig.setPrivateKey(privateKey);
58 | }
59 | if (ObjectUtil.isEmpty(ossConfig.getCustomHost())) {
60 | ossConfig.setCustomHost(customHost);
61 | }
62 | if (ObjectUtil.isEmpty(ossConfig.getClientConfig())) {
63 | ossConfig.setClientConfig(clientConfig);
64 | }
65 | SpringUtil.registerBean(name, uCloudOssClient(ossConfig));
66 | });
67 | }
68 | return null;
69 | }
70 |
71 | public StandardOssClient uCloudOssClient(UCloudOssConfig uCloudOssConfig) {
72 | UCloudOssClientConfig clientConfig = Optional.ofNullable(uCloudOssConfig.getClientConfig()).orElse(new UCloudOssClientConfig());
73 | UfileClient.Config config = new UfileClient.Config(clientConfig.toClientConfig());
74 | ObjectAuthorization objectAuthorization = new UfileObjectLocalAuthorization(uCloudOssConfig.getPublicKey(), uCloudOssConfig.getPrivateKey());
75 | ObjectConfig objectConfig = new ObjectConfig(uCloudOssConfig.getCustomHost());
76 | UfileClient ufileClient = UfileClient.configure(config);
77 | ObjectApiBuilder objectApiBuilder = new ObjectApiBuilder(ufileClient, objectAuthorization, objectConfig);
78 | return new UCloudOssClient(ufileClient, objectApiBuilder, uCloudOssConfig);
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/up/UpOssConfiguration.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.up;
2 |
3 | import cn.hutool.core.text.CharPool;
4 | import cn.hutool.core.util.ObjectUtil;
5 | import cn.hutool.extra.spring.SpringUtil;
6 | import com.upyun.ParallelUploader;
7 | import com.upyun.RestManager;
8 | import io.github.artislong.constant.OssConstant;
9 | import io.github.artislong.core.StandardOssClient;
10 | import io.github.artislong.core.up.model.UpOssClientConfig;
11 | import io.github.artislong.core.up.model.UpOssConfig;
12 | import io.github.artislong.model.SliceConfig;
13 | import org.springframework.beans.factory.annotation.Autowired;
14 | import org.springframework.boot.SpringBootConfiguration;
15 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
16 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
17 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
18 | import org.springframework.context.annotation.Bean;
19 |
20 | import java.util.Map;
21 | import java.util.Optional;
22 |
23 | /**
24 | * @author 陈敏
25 | * @version UpOssConfiguration.java, v 1.1 2021/11/30 12:03 chenmin Exp $
26 | * Created on 2021/11/30
27 | */
28 | @SpringBootConfiguration
29 | @ConditionalOnClass(RestManager.class)
30 | @EnableConfigurationProperties({UpOssProperties.class})
31 | @ConditionalOnProperty(prefix = OssConstant.OSS, name = OssConstant.OssType.UP + CharPool.DOT + OssConstant.ENABLE,
32 | havingValue = OssConstant.DEFAULT_ENABLE_VALUE)
33 | public class UpOssConfiguration {
34 |
35 | public static final String DEFAULT_BEAN_NAME = "upOssClient";
36 |
37 | @Autowired
38 | private UpOssProperties upOssProperties;
39 |
40 | @Bean
41 | public StandardOssClient upOssClient() {
42 | Map upOssConfigMap = upOssProperties.getOssConfig();
43 | if (upOssConfigMap.isEmpty()) {
44 | SpringUtil.registerBean(DEFAULT_BEAN_NAME, upOssClient(upOssProperties));
45 | } else {
46 | String userName = upOssProperties.getUserName();
47 | String password = upOssProperties.getPassword();
48 | upOssConfigMap.forEach((name, upOssConfig) -> {
49 | if (ObjectUtil.isEmpty(upOssConfig.getUserName())) {
50 | upOssConfig.setUserName(userName);
51 | }
52 | if (ObjectUtil.isEmpty(upOssConfig.getPassword())) {
53 | upOssConfig.setPassword(password);
54 | }
55 | SpringUtil.registerBean(name, upOssClient(upOssConfig));
56 | });
57 | }
58 | return null;
59 | }
60 |
61 | private StandardOssClient upOssClient(UpOssConfig upOssConfig) {
62 | RestManager restManager = restManager(upOssConfig);
63 | ParallelUploader parallelUploader = parallelUploader(upOssConfig);
64 | return upOssClient(restManager, parallelUploader, upOssConfig);
65 | }
66 |
67 | public StandardOssClient upOssClient(RestManager restManager, ParallelUploader parallelUploader, UpOssConfig upOssConfig) {
68 | return new UpOssClient(restManager, parallelUploader, upOssConfig);
69 | }
70 |
71 | public RestManager restManager(UpOssConfig upOssConfig) {
72 | RestManager restManager = new RestManager(upOssConfig.getBucketName(), upOssConfig.getUserName(), upOssConfig.getPassword());
73 | UpOssClientConfig clientConfig = Optional.ofNullable(upOssConfig.getClientConfig()).orElse(new UpOssClientConfig());
74 | // 手动设置超时时间:默认为30秒
75 | restManager.setTimeout(clientConfig.getTimeout());
76 | // 选择最优的接入点
77 | restManager.setApiDomain(clientConfig.getApiDomain().toString());
78 | return restManager;
79 | }
80 |
81 | public ParallelUploader parallelUploader(UpOssConfig upOssConfig) {
82 | ParallelUploader parallelUploader = new ParallelUploader(upOssConfig.getBucketName(), upOssConfig.getUserName(), upOssConfig.getPassword());
83 |
84 | SliceConfig sliceConfig = upOssConfig.getSliceConfig();
85 | parallelUploader.setParallel(sliceConfig.getTaskNum());
86 | parallelUploader.setCheckMD5(true);
87 | UpOssClientConfig clientConfig = Optional.ofNullable(upOssConfig.getClientConfig()).orElse(new UpOssClientConfig());
88 | parallelUploader.setTimeout(clientConfig.getTimeout());
89 | return parallelUploader;
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/baidu/model/BaiduOssClientConfig.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.baidu.model;
2 |
3 | import cn.hutool.core.bean.BeanUtil;
4 | import cn.hutool.core.util.ObjectUtil;
5 | import com.baidubce.BceClientConfiguration;
6 | import com.baidubce.Protocol;
7 | import com.baidubce.Region;
8 | import com.baidubce.http.DefaultRetryPolicy;
9 | import com.baidubce.http.RetryPolicy;
10 | import com.baidubce.services.bos.BosClientConfiguration;
11 | import io.github.artislong.core.baidu.constant.BaiduOssConstant;
12 | import lombok.Data;
13 | import lombok.experimental.Accessors;
14 | import lombok.extern.slf4j.Slf4j;
15 |
16 | import java.net.InetAddress;
17 | import java.net.UnknownHostException;
18 |
19 | import static com.baidubce.BceClientConfiguration.*;
20 | import static com.baidubce.services.bos.BosClientConfiguration.*;
21 |
22 | /**
23 | * @author 陈敏
24 | * @version BaiduOssClientConfig.java, v 1.0 2022/4/20 16:19 chenmin Exp $
25 | * Created on 2022/4/20
26 | */
27 | @Slf4j
28 | @Data
29 | @Accessors(chain = true)
30 | public class BaiduOssClientConfig {
31 | /**
32 | * 使用cname访问BOS资源
33 | */
34 | private boolean cnameEnabled;
35 | /**
36 | * 异步put
37 | */
38 | private boolean enableHttpAsyncPut = true;
39 | /**
40 | * 建立连接的超时时间(单位:毫秒)
41 | */
42 | private int connectionTimeoutInMillis = DEFAULT_CONNECTION_TIMEOUT_IN_MILLIS;
43 | /**
44 | * 允许打开的最大HTTP连接数
45 | */
46 | private int maxConnections = DEFAULT_MAX_CONNECTIONS;
47 | /**
48 | * 连接协议类型
49 | */
50 | private Protocol protocol = DEFAULT_PROTOCOL;
51 | /**
52 | * 访问NTLM验证的代理服务器的Windows域名
53 | */
54 | private String proxyDomain;
55 | /**
56 | * 代理服务器主机地址
57 | */
58 | private String proxyHost;
59 | /**
60 | * 代理服务器验证的密码
61 | */
62 | private String proxyPassword;
63 | /**
64 | * 代理服务器端口
65 | */
66 | private int proxyPort = -1;
67 | /**
68 | * 代理服务器验证的用户名
69 | */
70 | private String proxyUsername;
71 | /**
72 | * NTLM代理服务器的Windows工作站名称
73 | */
74 | private String proxyWorkstation;
75 | /**
76 | * 是否设置用户代理认证
77 | */
78 | private boolean proxyPreemptiveAuthenticationEnabled;
79 | /**
80 | * 通过打开的连接传输数据的超时时间(单位:毫秒)
81 | */
82 | private int socketTimeoutInMillis = DEFAULT_SOCKET_TIMEOUT_IN_MILLIS;
83 | /**
84 | * Socket缓冲区大小
85 | */
86 | private int socketBufferSizeInBytes = 0;
87 | /**
88 | * 访问域名
89 | */
90 | private String endpoint = BaiduOssConstant.DEFAULT_ENDPOINT;
91 | /**
92 | * 地域
93 | */
94 | private Region region = DEFAULT_REGION;
95 | /**
96 | * 是否开启HTTP重定向。默认开启
97 | */
98 | private boolean redirectsEnabled = true;
99 | /**
100 | * 本地地址
101 | */
102 | private String localAddress;
103 | /**
104 | * 请求失败最大重试次数
105 | */
106 | private int maxErrorRetry = RetryPolicy.DEFAULT_MAX_ERROR_RETRY;
107 | /**
108 | * 最大延迟时间,单位:毫秒
109 | */
110 | private long maxDelayInMillis = RetryPolicy.DEFAULT_MAX_DELAY_IN_MILLIS;
111 | /**
112 | * 流文件缓冲区大小
113 | */
114 | private int streamBufferSize = DEFAULT_STREAM_BUFFER_SIZE;
115 | /**
116 | * 用户代理,指HTTP的User-Agent头
117 | */
118 | private String userAgent = BceClientConfiguration.DEFAULT_USER_AGENT;
119 |
120 | public BosClientConfiguration toClientConfig() {
121 | BosClientConfiguration clientConfig = new BosClientConfiguration();
122 | BeanUtil.copyProperties(this, clientConfig, "proxyPort", "socketBufferSizeInBytes",
123 | "localAddress", "maxErrorRetry", "maxDelayInMillis");
124 | if (this.proxyPort != -1) {
125 | clientConfig.setProxyPort(this.proxyPort);
126 | }
127 | if (this.socketBufferSizeInBytes != 0) {
128 | clientConfig.setSocketBufferSizeInBytes(this.socketBufferSizeInBytes);
129 | }
130 | if (ObjectUtil.isNotEmpty(this.localAddress)) {
131 | try {
132 | clientConfig.setLocalAddress(InetAddress.getByName(this.localAddress));
133 | } catch (UnknownHostException e) {
134 | log.error("localAddress配置有误,请检查!", e);
135 | }
136 | }
137 | clientConfig.setRetryPolicy(new DefaultRetryPolicy(maxErrorRetry, maxDelayInMillis));
138 | return clientConfig;
139 | }
140 | }
141 |
--------------------------------------------------------------------------------
/src/main/java/io/github/artislong/core/minio/MinioOssConfiguration.java:
--------------------------------------------------------------------------------
1 | package io.github.artislong.core.minio;
2 |
3 | import cn.hutool.core.text.CharPool;
4 | import cn.hutool.core.util.ObjectUtil;
5 | import cn.hutool.extra.spring.SpringUtil;
6 | import io.github.artislong.constant.OssConstant;
7 | import io.github.artislong.core.StandardOssClient;
8 | import io.github.artislong.core.minio.model.MinioOssClientConfig;
9 | import io.github.artislong.core.minio.model.MinioOssConfig;
10 | import io.minio.MinioClient;
11 | import okhttp3.OkHttpClient;
12 | import org.springframework.beans.factory.annotation.Autowired;
13 | import org.springframework.boot.SpringBootConfiguration;
14 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
15 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
16 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
17 | import org.springframework.context.annotation.Bean;
18 |
19 | import java.util.Map;
20 | import java.util.concurrent.TimeUnit;
21 |
22 | /**
23 | * @author 陈敏
24 | * @version MinioConfiguration.java, v 1.1 2021/11/24 15:20 chenmin Exp $
25 | * Created on 2021/11/24
26 | */
27 | @SpringBootConfiguration
28 | @ConditionalOnClass(MinioClient.class)
29 | @EnableConfigurationProperties({MinioOssProperties.class})
30 | @ConditionalOnProperty(prefix = OssConstant.OSS, name = OssConstant.OssType.MINIO + CharPool.DOT + OssConstant.ENABLE,
31 | havingValue = OssConstant.DEFAULT_ENABLE_VALUE)
32 | public class MinioOssConfiguration {
33 |
34 | public static final String DEFAULT_BEAN_NAME = "minioOssClient";
35 |
36 | @Autowired
37 | private MinioOssProperties minioOssProperties;
38 |
39 | @Bean
40 | public StandardOssClient minioOssClient() {
41 | Map minioOssConfigMap = minioOssProperties.getOssConfig();
42 | if (minioOssConfigMap.isEmpty()) {
43 | SpringUtil.registerBean(DEFAULT_BEAN_NAME, minioOssClient(minioOssProperties));
44 | } else {
45 | String endpoint = minioOssProperties.getEndpoint();
46 | String accessKey = minioOssProperties.getAccessKey();
47 | String secretKey = minioOssProperties.getSecretKey();
48 | MinioOssClientConfig clientConfig = minioOssProperties.getClientConfig();
49 | minioOssConfigMap.forEach((name, minioOssConfig) -> {
50 | if (ObjectUtil.isEmpty(minioOssConfig.getEndpoint())) {
51 | minioOssConfig.setEndpoint(endpoint);
52 | }
53 | if (ObjectUtil.isEmpty(minioOssConfig.getAccessKey())) {
54 | minioOssConfig.setAccessKey(accessKey);
55 | }
56 | if (ObjectUtil.isEmpty(minioOssConfig.getSecretKey())) {
57 | minioOssConfig.setSecretKey(secretKey);
58 | }
59 | if (ObjectUtil.isEmpty(minioOssConfig.getClientConfig())) {
60 | minioOssConfig.setClientConfig(clientConfig);
61 | }
62 | SpringUtil.registerBean(name, minioOssClient(minioOssConfig));
63 | });
64 | }
65 | return null;
66 | }
67 |
68 | public StandardOssClient minioOssClient(MinioOssConfig minioOssConfig) {
69 | return new MinioOssClient(minioClient(minioOssConfig), minioOssConfig);
70 | }
71 |
72 | public MinioClient minioClient(MinioOssConfig minioOssConfig) {
73 | MinioOssClientConfig clientConfig = minioOssConfig.getClientConfig();
74 | OkHttpClient okHttpClient = new OkHttpClient.Builder()
75 | .connectTimeout(clientConfig.getConnectTimeout(), TimeUnit.MILLISECONDS)
76 | .writeTimeout(clientConfig.getWriteTimeout(), TimeUnit.MILLISECONDS)
77 | .readTimeout(clientConfig.getReadTimeout(), TimeUnit.MILLISECONDS)
78 | .callTimeout(clientConfig.getCallTimeout(), TimeUnit.MILLISECONDS)
79 | .followRedirects(clientConfig.isFollowRedirects())
80 | .followSslRedirects(clientConfig.isFollowSslRedirects())
81 | .retryOnConnectionFailure(clientConfig.isRetryOnConnectionFailure())
82 | .pingInterval(clientConfig.getPingInterval(), TimeUnit.MILLISECONDS)
83 | .build();
84 | return MinioClient.builder()
85 | .endpoint(minioOssConfig.getEndpoint())
86 | .credentials(minioOssConfig.getAccessKey(), minioOssConfig.getSecretKey())
87 | .httpClient(okHttpClient)
88 | .build();
89 | }
90 | }
91 |
--------------------------------------------------------------------------------