Tencent Cloud COS cloud object storage, distributed solution signature upload

Yesterday I wrote about Alibaba Cloud’s OSS object storage signature upload, and today I will summarize Tencent Cloud’s. It is very simple. I won’t say more about the activation steps and sub-user activation and authorization. It is analogous to the previous blog: https://blog
. csdn.net/m0_57249797/article/details/124748601?spm=1001.2014.3001.5501

Directly upload the back-end signature code:
Maven dependency:

		<dependency>
            <groupId>com.qcloud</groupId>
            <artifactId>cos_api</artifactId>
            <version>5.6.54</version>
        </dependency>

backend code

 @GetMapping("test")
    public String doGet() {
    
    
        // 1 初始化用户身份信息(secretId, secretKey)
        COSCredentials cred = new BasicCOSCredentials("你的secretId", "你的secretKey");
        // 2 设置bucket的区域, COS地域的简称请参照 https://cloud.tencent.com/document/product/436/6224
        ClientConfig clientConfig = new ClientConfig(new Region("ap-nanjing"));
        // 3 生成 cos 客户端
        COSClient cosclient = new COSClient(cred, clientConfig);
        // bucket名需包含appid
        String bucketName = "填你的桶名字";
        String key = "test.jpeg";
        Date expirationTime = new Date(System.currentTimeMillis() + 30 * 60 * 1000);
//        HashMap<String, String> headers = new HashMap<>();
//        headers.put("Content-Type","image/jpeg");
        // 生成预签名上传 URL
        URL url = cosclient.generatePresignedUrl(bucketName, key, expirationTime, HttpMethodName.PUT, new HashMap<>(), new HashMap<>());
        return url.toString();
    }

Postman sends a request to get a signed link:
insert image description here

Postman takes the signature upload link and uploads the file binary stream (if you use a form to upload, the request method is post, and you must also bring "key: file name" and "Content-Type: image/jpeg" to upload successfully) PUT
upload
insert image description here
Click Check the upload result after uploading:
insert image description here
Get the request access address splicing and don’t write it, I wrote it before, you can ask me for more principles, or read the previous blog about Alibaba Cloud

Guess you like

Origin blog.csdn.net/m0_57249797/article/details/124766809