Parcourir la source

'修改成cos'

Althars123 il y a 4 ans
Parent
commit
9ed12e50cf

+ 42 - 80
zzjs-admin/src/main/java/com/miaxis/system/controller/common/CommonController.java

@@ -1,7 +1,5 @@
 package com.miaxis.system.controller.common;
 
-import com.miaxis.common.aliyunOSS.AliyunConfig;
-import com.miaxis.common.aliyunOSS.AliyunUpload;
 import com.miaxis.common.annotation.Log;
 import com.miaxis.common.config.MiaxisConfig;
 import com.miaxis.common.constant.Constants;
@@ -15,10 +13,20 @@ import com.miaxis.common.utils.file.FileUtils;
 import com.miaxis.file.domain.FileInfo;
 import com.miaxis.file.service.IFileInfoService;
 import com.miaxis.framework.config.ServerConfig;
-import io.swagger.annotations.*;
+import com.qcloud.cos.COSClient;
+import com.qcloud.cos.ClientConfig;
+import com.qcloud.cos.auth.BasicCOSCredentials;
+import com.qcloud.cos.auth.COSCredentials;
+import com.qcloud.cos.model.PutObjectRequest;
+import com.qcloud.cos.model.PutObjectResult;
+import com.qcloud.cos.region.Region;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestParam;
@@ -27,9 +35,9 @@ import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import java.io.File;
 import java.io.IOException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
+import java.util.Calendar;
 
 /**
  * 通用请求处理
@@ -48,6 +56,16 @@ public class CommonController
     @Autowired
     private IFileInfoService fileInfoService;
 
+    @Value("${cos.bucketName}")
+    private String bucketName;
+    @Value("${cos.path}")
+    private String path;
+    @Value("${cos.preffix}")
+    private String preffix;
+
+    @Autowired
+    COSClient  cosClient;
+
 
 
     /**
@@ -56,9 +74,6 @@ public class CommonController
     @Log(title = "上传文件", businessType = BusinessTypeEnum.INSERT)
     @PostMapping(Constants.OPEN_PREFIX+"/common/file")
     @ApiOperation("通用上传请求")
-//    @ApiImplicitParams({
-//            @ApiImplicitParam(name = "fileType",value = "业务类型:1-举报图片 99-其他" ,dataType = "int", paramType = "query", required = true)
-//    })
     public Response<FileInfo> updateload(MultipartFile file,
                                          @ApiParam(name = "fileType", value = "业务类型:98-音视频文件、1-商户logo、99-其他")
         @RequestParam("fileType") Integer fileType) throws IOException {
@@ -71,87 +86,34 @@ public class CommonController
         if (!validateFileSuffix(suffix,fileUploadTypeEnum)){
             throw new CustomException("文件类型不合法");
         }
+
+        // bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式
+        String bucketName = this.bucketName;
+        // 简单文件上传, 最大支持 5 GB, 适用于小文件上传, 建议 20 M 以下的文件使用该接口
+        // 大文件上传请参照 API 文档高级 API 上传
+        File localFile = null;
+        localFile = File.createTempFile("temp",null);
+        file.transferTo(localFile);
+        Calendar cal = Calendar.getInstance();
+        int year = cal.get(Calendar.YEAR);
+        int month=cal.get(Calendar.MONTH)+ 1;
+        int day=cal.get(Calendar.DATE);
         //存储的文件名
         String storagefileName = System.currentTimeMillis() + suffix;
-        String savePath = AliyunConfig.ZZJS_PATH
-                + new SimpleDateFormat("yyyy-MM-dd").format(new Date()) +"/"+
-                fileUploadTypeEnum.getFileType() +"/";
-        String fileUrl = AliyunUpload.uploadForStream(file.getInputStream(), savePath, storagefileName);
+        // 指定要上传到 COS 上的路径
+        String key = "/"+this.preffix+"/"+fileUploadTypeEnum.getFileType()+"/"+year+"/"+month+"/"+day+"/"+storagefileName;
+        PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key, localFile);
+        PutObjectResult putObjectResult = cosClient.putObject(putObjectRequest);
+        String fileUrl=this.path + putObjectRequest.getKey();
+
         FileInfo fileInfo = new FileInfo();
         fileInfo.setFileType(fileUploadTypeEnum.getFileType());
-        fileInfo.setFilePath(savePath+storagefileName);
+        fileInfo.setFilePath(key+storagefileName);
         fileInfo.setFileUrl(fileUrl);
         fileInfoService.save(fileInfo);
         return Response.success(fileInfo);
     }
 
-//    /**
-//     * 通用下载请求
-//     *
-//     * @param fileName 文件名称
-//     * @param delete 是否删除
-//     */
-//    @GetMapping("common/download")
-//    @ApiOperation("通用下载请求")
-//    public void fileDownload(
-//            @ApiParam(name = "fileName", value = "文件名称")
-//            @RequestParam(name = "fileName", required = true) String fileName,
-//            @ApiParam(name = "delete", value = "是否删除")
-//            @RequestParam(name = "delete", required = true) Boolean delete,
-//            HttpServletResponse response,
-//            HttpServletRequest request)
-//    {
-//        try
-//        {
-//            if (!FileUtils.isValidFilename(fileName))
-//            {
-//                throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", fileName));
-//            }
-//            String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1);
-//            String filePath = MiaxisConfig.getDownloadPath() + fileName;
-//
-//            response.setCharacterEncoding("utf-8");
-//            response.setContentType("multipart/form-data");
-//            response.setHeader("Content-Disposition",
-//                    "attachment;fileName=" + FileUtils.setFileDownloadHeader(request, realFileName));
-//            FileUtils.writeBytes(filePath, response.getOutputStream());
-//            if (delete)
-//            {
-//                FileUtils.deleteFile(filePath);
-//            }
-//        }
-//        catch (Exception e)
-//        {
-//            log.error("下载文件失败", e);
-//        }
-//    }
-
-//    /**
-//     * 通用上传请求
-//     */
-//    @PostMapping("/common/upload")
-//    @ApiOperation("通用上传请求")
-//    public Response<UploadFileDTO> uploadFile(MultipartFile file) throws Exception
-//    {
-//        try
-//        {
-//            // 上传文件路径
-//            String filePath = MiaxisConfig.getUploadPath();
-//            // 上传并返回新文件名称
-//            String fileName = FileUploadUtils.upload(filePath, file);
-//            String url = serverConfig.getUrl() + fileName;
-//            UploadFileDTO uploadFileDTO = new UploadFileDTO();
-//            uploadFileDTO.setFileName(fileName);
-//            uploadFileDTO.setUrl(url);
-//
-//            return Response.success(uploadFileDTO);
-//        }
-//        catch (Exception e)
-//        {
-//            return Response.error().setMsg(e.getMessage());
-//        }
-//    }
-
     /**
      * 本地资源通用下载
      */

+ 2 - 0
zzjs-admin/src/main/java/com/miaxis/system/controller/system/SysLoginController.java

@@ -10,6 +10,7 @@ import com.miaxis.common.core.domain.model.LoginBodyNoCode;
 import com.miaxis.common.core.domain.model.LoginUser;
 import com.miaxis.common.enums.StudentLoginTypeEnum;
 import com.miaxis.common.utils.RandomNameUtils;
+import com.miaxis.common.utils.SecurityUtils;
 import com.miaxis.common.utils.ServletUtils;
 import com.miaxis.feign.dto.WxResult;
 import com.miaxis.feign.service.IWxService;
@@ -149,6 +150,7 @@ public class SysLoginController
     @ApiOperation("获取用户信息")
     public Response<UserInfoDTO> getInfo()
     {
+        SecurityUtils.getLoginUser();
         LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
         UserInfoDTO userInfoDTO = new UserInfoDTO();
         SysUser user = loginUser.getUser();

+ 10 - 0
zzjs-admin/src/main/resources/application.yml

@@ -215,4 +215,14 @@ app:
   appid: wx8f43db501343feab
   secret: 3509a81880669ffa6fa554b2aa050351
 
+# 腾讯cos
+cos:
+  secretId: AKIDwISNOFsJXYGjy89FJI9UnzuZFgTtRgFe
+  secretKey: IK5af8MJzPoKbdQxDCtKWR5T5PSEkyDB
+  bucket: ap-shanghai
+  bucketName: t1-1305573081
+  path: https://t1-1305573081.cos.ap-shanghai.myqcloud.com
+  preffix: t1
+
+
 

+ 7 - 0
zzjs-common/pom.xml

@@ -145,6 +145,13 @@
             <version>11.2.0.3</version>
         </dependency>
 
+        <!--腾讯云存储依赖-->
+        <dependency>
+            <groupId>com.qcloud</groupId>
+            <artifactId>cos_api</artifactId>
+            <version>5.6.38</version>
+        </dependency>
+
 
         <!-- swagger2-->
         <dependency>

+ 0 - 15
zzjs-common/src/main/java/com/miaxis/common/aliyunOSS/AliyunConfig.java

@@ -1,15 +0,0 @@
-package com.miaxis.common.aliyunOSS;
-
-public class AliyunConfig {
-	public static String ENDPOINT = "oss-cn-shanghai.aliyuncs.com";
-	public static String ACCESSKEYID = "LTAIijc2Vl913Dha";
-	public static String ACCESSKEYSECRET = "HbQBG0RQqdfKoYGJmoqdT1FFYO8OTs";
-	public static String BUCKETNAME = "xzzfile";
-	public static String VISITPATH = "http://image.jppt.com.cn";
-
-	public static String ZZJS_PATH = "zzjs/";
-
-
-
-
-}

+ 0 - 69
zzjs-common/src/main/java/com/miaxis/common/aliyunOSS/AliyunDown.java

@@ -1,69 +0,0 @@
-package com.miaxis.common.aliyunOSS;
-
-import com.aliyun.oss.OSSClient;
-import com.aliyun.oss.model.DownloadFileRequest;
-import com.aliyun.oss.model.DownloadFileResult;
-import com.aliyun.oss.model.GetObjectRequest;
-
-import java.io.File;
-
-public class AliyunDown {
-
-	/**
-	 * 通过URL地址,从阿里云下载文件到指定目录,
-	 * @param  url 阿里的访问地址,必须是我们自己上传的文件才能有效
-	 * @param  savePath 保存在本地的地址
-	 * */
-	public static boolean  downAliyunFromUrlTolLocalFile(String url,String savePath){
-		OSSClient ossClient = new OSSClient(AliyunConfig.ENDPOINT, AliyunConfig.ACCESSKEYID,AliyunConfig.ACCESSKEYSECRET);
-
-		try {
-			String key = url.replaceAll(AliyunConfig.VISITPATH, "");
-			key = key.replace("/tms", "tms");
-
-			ossClient.getObject(new GetObjectRequest(AliyunConfig.BUCKETNAME, key), new File(savePath));
-			return true;
-		} catch (Exception e) {
-			e.printStackTrace();
-			return false;
-		}finally{
-			ossClient.shutdown();
-		}
-	}
-	
-	/**
-	 * 通过URL地址,从阿里云下载文件到指定目录,
-	 * @param  url 阿里的访问地址,必须是我们自己上传的文件才能有效
-	 * @param  savePath 保存在本地的地址
-	 * */
-	public static boolean  downBigFileAliyunFromUrlTolLocalFile(String url,String savePath){
-		OSSClient ossClient = new OSSClient(AliyunConfig.ENDPOINT, AliyunConfig.ACCESSKEYID,AliyunConfig.ACCESSKEYSECRET);
-		try {
-			String key = url.replaceAll(AliyunConfig.VISITPATH, "");
-			System.out.println(key);
-			//ossClient.getObject(new GetObjectRequest(AliyunConfig.BUCKETNAME, key), new File(savePath));
-			// 下载请求,10个任务并发下载,启动断点续传
-			DownloadFileRequest downloadFileRequest = new DownloadFileRequest(AliyunConfig.BUCKETNAME, key);
-			downloadFileRequest.setDownloadFile(savePath);
-			downloadFileRequest.setTaskNum(10);
-			downloadFileRequest.setEnableCheckpoint(true);
-			// 下载文件
-			DownloadFileResult downloadRes = ossClient.downloadFile(downloadFileRequest);
-			// 下载成功时,会返回文件的元信息
-			downloadRes.getObjectMetadata();
-			return true;
-		} catch (Exception e) {
-			e.printStackTrace();
-			return false;
-		} catch (Throwable e) {
-			e.printStackTrace();
-			return false;
-		}finally{
-			ossClient.shutdown();
-		}
-	}
-	public static void main(String[] args) {
-		String url = "http://image.lnjppt.com/tms/sld/2101000000001-1.pdf";
-		downAliyunFromUrlTolLocalFile(url.replace("http://image.lnjppt.com/", ""), "E://temp.pdf");
-	}
-}

+ 0 - 251
zzjs-common/src/main/java/com/miaxis/common/aliyunOSS/AliyunUpload.java

@@ -1,251 +0,0 @@
-package com.miaxis.common.aliyunOSS;
-
-import com.aliyun.oss.OSSClient;
-import com.miaxis.common.core.domain.Response;
-import com.miaxis.common.utils.Base64;
-import sun.misc.BASE64Decoder;
-
-import java.io.*;
-import java.net.URL;
-import java.net.URLEncoder;
-
-public class AliyunUpload {
-
-	@SuppressWarnings("restriction")
-	public static byte[] getByteFormString(String content){
-		BASE64Decoder decoder = new BASE64Decoder();
-		byte[] sourceBytes  = null;
-		try {
-			sourceBytes = decoder.decodeBuffer(content);
-			for (int i = 0; i < sourceBytes.length; ++i) {
-				if (sourceBytes[i] < 0) {// 调整异常数据
-					sourceBytes[i] += 256;
-				}
-			}
-		} catch (Exception e) {
-			// TODO: handle exception
-		}
-		
-		return sourceBytes;
-	}
-	/**
-	 * 上传byte数组
-	 * @param  content 比如"Hello OSS".getBytes();
-	 * @param  savePath 保存的路径
-	 * @param  fileName 上传文件的名称包含后坠
-	 * @return 如果上传成功返回访问地址,如果失败返回"";
-	 * */
-	@SuppressWarnings("deprecation")
-	public static String uploadForByte(byte[] content,String savePath,String fileName){
-		OSSClient ossClient = new OSSClient(AliyunConfig.ENDPOINT, AliyunConfig.ACCESSKEYID,AliyunConfig.ACCESSKEYSECRET);
-		String url = "";
-		try {
-			String key = savePath+fileName;
-			ossClient.putObject(AliyunConfig.BUCKETNAME, key, new ByteArrayInputStream(content));
-			url = AliyunConfig.VISITPATH+"/"+savePath+URLEncoder.encode(fileName);
-		} catch (Exception e) {
-			e.printStackTrace();
-			return null;
-		}finally{
-			ossClient.shutdown();
-		}
-		return url;
-	}
-	/**
-	 * 上传本地文件
-	 * @param  file 如new File("d://1.jpg")
-	 * @param  savePath 保存的路径 如 D://1.jpg
-	 * @param  fileName 上传文件的名称 1.jpg
-	 * @return 如果上传成功返回访问地址,如果失败返回"";
-	 * */
-	@SuppressWarnings("deprecation")
-	public static String uploadForLocalFile(File file, String savePath,String fileName){
-		OSSClient ossClient = new OSSClient(AliyunConfig.ENDPOINT, AliyunConfig.ACCESSKEYID,AliyunConfig.ACCESSKEYSECRET);
-		String url = "";
-		try {
-			String key = savePath+fileName;
-			ossClient.putObject(AliyunConfig.BUCKETNAME, key, file);
-			url = AliyunConfig.VISITPATH+"/"+savePath+URLEncoder.encode(fileName);
-		} catch (Exception e) {
-			//e.printStackTrace();
-			return null;
-		}finally{
-			ossClient.shutdown();
-		}
-		return url;
-	}
-	/**
-	 * 上传文件流
-	 * @param   is 比如InputStream inputStream = new FileInputStream("localFile");
-	 * @param  savePath 保存的路径 如 D://1.jpg
-	 * @param  fileName 上传文件的名称 1.jpg
-	 * @return 如果上传成功返回访问地址,如果失败返回"";
-	 * */
-	@SuppressWarnings("deprecation")
-	public static String uploadForStream(InputStream  is, String savePath,String fileName){
-		OSSClient ossClient = new OSSClient(AliyunConfig.ENDPOINT, AliyunConfig.ACCESSKEYID,AliyunConfig.ACCESSKEYSECRET);
-		String url = "";
-		try {
-			String key = savePath+fileName;
-			ossClient.putObject(AliyunConfig.BUCKETNAME, key, is);
-			url = AliyunConfig.VISITPATH+"/"+savePath+URLEncoder.encode(fileName);
-		} catch (Exception e) {
-			e.printStackTrace();
-			return null;
-		}finally{
-			ossClient.shutdown();
-		}
-		return url;
-	}
-	/**
-	 * 上传网络流
-	 * @param  url 图片路径
-	 * @param  savePath 保存的路径 如 D://1.jpg
-	 * @param  fileName 上传文件的名称 1.jpg
-	 * @return 如果上传成功返回访问地址,如果失败返回"";
-	 * */
-	@SuppressWarnings("deprecation")
-	public static String uploadForUrl(String url, String savePath,String fileName){
-		OSSClient ossClient = new OSSClient(AliyunConfig.ENDPOINT, AliyunConfig.ACCESSKEYID,AliyunConfig.ACCESSKEYSECRET);
-		String path = "";
-		try {
-			String key = savePath+fileName;
-			InputStream inputStream = new URL(url).openStream();
-			ossClient.putObject(AliyunConfig.BUCKETNAME, key, inputStream);
-			path = AliyunConfig.VISITPATH+"/"+savePath+URLEncoder.encode(fileName);
-		} catch (Exception e) {
-			e.printStackTrace();
-			return null;
-		}finally{
-			ossClient.shutdown();
-		}
-		return path;
-	}
-	/**
-	 * 上传字符串
-	 * @param  content 上传的内容
-	 * @param  savePath 保存的路径 如 D://1.jpg
-	 * @param  fileName 上传文件的名称 1.jpg
-	 * @return 如果上传成功返回访问地址,如果失败返回"";
-	 * */
-	@SuppressWarnings("deprecation")
-	public static String uploadForString(String content, String savePath,String fileName){
-		OSSClient ossClient = new OSSClient(AliyunConfig.ENDPOINT, AliyunConfig.ACCESSKEYID,AliyunConfig.ACCESSKEYSECRET);
-		String path = "";
-		try {
-			String key = savePath+fileName;
-			ossClient.putObject(AliyunConfig.BUCKETNAME, key, new ByteArrayInputStream(content.getBytes()));
-			path = AliyunConfig.VISITPATH+"/"+savePath+URLEncoder.encode(fileName);
-		} catch (Exception e) {
-			e.printStackTrace();
-			return null;
-		}finally{
-			ossClient.shutdown();
-		}
-		return path;
-	}
-	public static void main1(String[] args) {
-		//OSSClient ossClient = new OSSClient("http://oss-cn-beijing.aliyuncs.com", "LTAIf6iXk0nNVS6R","V8XHqsYUBlcebbN1o3FqsntYepIifB");
-		String keyId= "LTAIijc2Vl913Dha";
-		String accessKey="HbQBG0RQqdfKoYGJmoqdT1FFYO8OTs";
-		OSSClient ossClient = new OSSClient("http://oss-cn-beijing.aliyuncs.com", keyId,accessKey);
-		String path = "";
-		try {
-			
-			String url = "http://218.60.2.212:8080/lnvideo/upload/weier/180228/20180228175702.mp4";
-			try {
-				 URL temp = new URL(url);  
-	             InputStream in = temp.openStream();  
-	             System.out.println("连接可用");  
-			} catch (Exception e) {
-				 System.out.println("连接不可用");  
-			}
-			
-			String key =  "video/"+url.replace("http://218.60.2.212:8080/lnvideo/", "");
-			//String fileName = url.substring(url.lastIndexOf("/"),url.length());
-			System.out.println(key);
-			//System.out.println(fileName);
-			InputStream inputStream = new URL(url).openStream();
-			ossClient.putObject("lnfile", key, inputStream);
-			path = AliyunConfig.VISITPATH+key;
-			System.out.println(path);
-		} catch (Exception e) {
-			e.printStackTrace();
-		}finally{
-			ossClient.shutdown();
-		}
-	}
-
-
-	public static String GetImageStr(String imgFile)  
-    {//将图片文件转化为字节数组字符串,并对其进行Base64编码处理  
-        //String imgFile = "F:\\36.jpg";//待处理的图片  
-        InputStream in = null;  
-        byte[] data = null;  
-        //读取图片字节数组  
-        try   
-        {  
-            in = new FileInputStream(imgFile);          
-            data = new byte[in.available()];  
-            in.read(data);  
-            in.close();  
-        }   
-        catch (IOException e)   
-        {  
-            e.printStackTrace();  
-        }  
-        //对字节数组Base64编码  
-        return Base64.encode(data);//返回Base64编码过的字节数组字符串
-    }  
-	
-	/**
-	 * 上传文件流
-	 * @param   is 比如InputStream inputStream = new FileInputStream("localFile");
-	 * @param  savePath 保存的路径 如 D://1.jpg
-	 * @param  fileName 上传文件的名称 1.jpg
-	 * @return 如果上传成功返回访问地址,如果失败返回"";
-	 * */
-	@SuppressWarnings("deprecation")
-	public static String uploadForGzptStream(InputStream  is, String savePath,String fileName){
-		OSSClient ossClient = new OSSClient(AliyunConfig.ENDPOINT, AliyunConfig.ACCESSKEYID,AliyunConfig.ACCESSKEYSECRET);
-		String url = "";
-		try {
-			String key = savePath+fileName;
-			ossClient.putObject(AliyunConfig.BUCKETNAME, key, is);
-			url = savePath+URLEncoder.encode(fileName);
-		} catch (Exception e) {
-			e.printStackTrace();
-			return null;
-		}finally{
-			ossClient.shutdown();
-		}
-		return url;
-	}
-
-    /**
-     * 删除文件
-     * @param filePath 文件
-     * @return
-     */
-    public static boolean deleteObject(String filePath) {
-        OSSClient ossClient = new OSSClient(AliyunConfig.ENDPOINT, AliyunConfig.ACCESSKEYID,AliyunConfig.ACCESSKEYSECRET);
-
-        try {
-            boolean exist = ossClient.doesObjectExist(AliyunConfig.BUCKETNAME,filePath);
-            if (!exist) {
-                System.out.println("文件不存在");
-                return false;
-            }
-            ossClient.deleteObject(AliyunConfig.BUCKETNAME,filePath);
-
-        }catch (Exception e){
-            e.printStackTrace();
-            System.out.println("服务异常");
-           return false;
-        }finally {
-            ossClient.shutdown();
-        }
-        return true;
-    }
-
-}

+ 47 - 0
zzjs-common/src/main/java/com/miaxis/common/config/BeanConfig.java

@@ -0,0 +1,47 @@
+package com.miaxis.common.config;
+
+import com.qcloud.cos.COSClient;
+import com.qcloud.cos.ClientConfig;
+import com.qcloud.cos.auth.BasicCOSCredentials;
+import com.qcloud.cos.auth.COSCredentials;
+import com.qcloud.cos.http.HttpProtocol;
+import com.qcloud.cos.region.Region;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+
+@Configuration
+public class BeanConfig {
+
+    @Value("${cos.secretId}")
+    private String secretId;
+    @Value("${cos.secretKey}")
+    private String secretKey;
+    @Value("${cos.bucket}")
+    private String bucket;
+    @Value("${cos.bucketName}")
+    private String bucketName;
+    @Value("${cos.path}")
+    private String path;
+    @Value("${cos.preffix}")
+    private String preffix;
+
+
+    @Bean
+    public COSClient  configBean() {
+        // 1 初始化用户身份信息(secretId, secretKey)。
+        String secretId = this.secretId;
+        String secretKey = this.secretKey;
+        COSCredentials cred = new BasicCOSCredentials(secretId, secretKey);
+        // 2 设置 bucket 的地域, COS 地域的简称请参照 https://cloud.tencent.com/document/product/436/6224
+        // clientConfig 中包含了设置 region, https(默认 http), 超时, 代理等 set 方法, 使用可参见源码或者常见问题 Java SDK 部分。
+        Region region = new Region(this.bucket);
+        ClientConfig clientConfig = new ClientConfig(region);
+        // 这里建议设置使用 https 协议
+        clientConfig.setHttpProtocol(HttpProtocol.https);
+        // 3 生成 cos 客户端。
+        COSClient cosClient = new COSClient(cred, clientConfig);
+        return cosClient;
+    }
+}