|
@@ -14,11 +14,14 @@ import java.io.File;
|
|
|
import java.io.InputStream;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
|
|
|
/**
|
|
|
* @author zhongcp
|
|
|
* @Date 2021/9/18
|
|
|
*/
|
|
|
+@Component
|
|
|
public class QcloudFileUtils {
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(QcloudFileUtils.class);
|
|
@@ -26,13 +29,33 @@ public class QcloudFileUtils {
|
|
|
static COSClient cosClient = createCli();
|
|
|
|
|
|
static COSClient createCli() {
|
|
|
- return createCli("ap-shanghai");
|
|
|
+ return createCli(region);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String accessKey;
|
|
|
+
|
|
|
+ @Value("${cloud.accessKey}")
|
|
|
+ public void setAccessKey(String accessKey) {
|
|
|
+ accessKey = accessKey;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String secretKey;
|
|
|
+
|
|
|
+ @Value("${cloud.secretKey}")
|
|
|
+ public void setSecretKey(String secretKey) {
|
|
|
+ secretKey = secretKey;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String region;
|
|
|
+
|
|
|
+ @Value("${cloud.region}")
|
|
|
+ public void setRegion(String region) {
|
|
|
+ secretKey = region;
|
|
|
}
|
|
|
|
|
|
static COSClient createCli(String region) {
|
|
|
// 初始化用户身份信息(secretId, secretKey)
|
|
|
- COSCredentials cred = new BasicCOSCredentials("AKIDDF4dwzlGVTAmCMGvLVP4UfbHiuqVzFEw",
|
|
|
- "TgbFcjZ8HDse9ToujIabLo1yf5YqtfBX");
|
|
|
+ COSCredentials cred = new BasicCOSCredentials(accessKey, secretKey);
|
|
|
// 设置bucket的区域, COS地域的简称请参照 https://www.qcloud.com/document/product/436/6224
|
|
|
ClientConfig clientConfig = new ClientConfig(new Region(region));
|
|
|
// 生成cos客户端
|