61 lines
1.3 KiB
Java
61 lines
1.3 KiB
Java
package com.agri.common.config;
|
|
|
|
import com.aliyun.oss.OSS;
|
|
import com.aliyun.oss.OSSClientBuilder;
|
|
import lombok.Data;
|
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
@Component("ossConfig")
|
|
@ConfigurationProperties(prefix = "aliyun.oss")
|
|
@Data
|
|
public class OSSConfig {
|
|
/**
|
|
* OSS 访问域名
|
|
*/
|
|
private String endpoint;
|
|
/**
|
|
* 标识用户
|
|
*/
|
|
private String accessKeyId;
|
|
/**
|
|
* 加密签名字符串
|
|
*/
|
|
private String accessKeySecret;
|
|
/**
|
|
* 存储空间名称
|
|
*/
|
|
private String bucketName;
|
|
|
|
/**
|
|
* 文件/对象名称的前缀,类似目录
|
|
*/
|
|
private String prefixKey;
|
|
/**
|
|
* 自定义域名,预览图片用到
|
|
*/
|
|
private String domainName;
|
|
/**
|
|
* 文件大小限制(单位: m)
|
|
*/
|
|
private Long maxSize;
|
|
|
|
/**
|
|
* 上传方式
|
|
*/
|
|
private String uploadType;
|
|
|
|
@Bean
|
|
public OSS ossClient() {
|
|
return new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
|
|
}
|
|
|
|
public Long getMaxSize() {
|
|
if (maxSize == null || maxSize == 0) {
|
|
maxSize = 10L;
|
|
}
|
|
return maxSize * 1024 * 1204;
|
|
}
|
|
}
|