package xyz.lengmaomao.lengblog.config;
import com.qcloud.cos.COSClient;
import com.qcloud.cos.ClientConfig;
import com.qcloud.cos.auth.BasicCOSCredentials;
import com.qcloud.cos.http.HttpProtocol;
import com.qcloud.cos.region.Region;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
/**
* @program: blog
* @description
* @author: szn
* @create: 2022-03-01 23:16
* 使用autowired注入CosClient
**/
@Component
public class TencentStoreConfig {
private String secretId = "这里是你的id";
private String secretKey = "这里是你的key";
private String cos_region = "这里是你的存储桶所在地";
/**
* 初始化用户身份
*/
@Bean
public BasicCOSCredentials getBasicCOSCredentials(){
return new BasicCOSCredentials(secretId, secretKey);
}
/**
* // 2 设置 bucket 的地域, COS 地域的简称请参照 https://cloud.tencent.com/document/product/436/6224
* // clientConfig 中包含了设置 region, https(默认 http), 超时, 代理等 set 方法, 使用可参见源码或者常见问题 Java SDK 部分。
* @return
*/
@Bean
public ClientConfig getClientConfig(){
Region region = new Region(cos_region);
ClientConfig clientConfig = new ClientConfig(region);
clientConfig.setHttpProtocol(HttpProtocol.https);
return clientConfig;
}
@Bean
public COSClient getCosClient(BasicCOSCredentials cred, ClientConfig clientConfig){
return new COSClient(cred, clientConfig);
}
}
07-14
4372
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-10
4441
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)