昨天寫(xiě)了阿里云的OSS對(duì)象存儲(chǔ)簽名上傳,今天把騰訊云的也總結(jié)一下,非常簡(jiǎn)單,開(kāi)通步驟和開(kāi)通子用戶(hù)并授權(quán)就不再多說(shuō),類(lèi)比上一篇博客:
https://blog.csdn.net/m0_57249797/article/details/124748601?spm=1001.2014.3001.5501
直接上后端簽名代碼:
Maven依賴(lài):
<dependency>
<groupId>com.qcloud</groupId>
<artifactId>cos_api</artifactId>
<version>5.6.54</version>
</dependency>
后端代碼
@GetMapping("test")
public String doGet() {
// 1 初始化用戶(hù)身份信息(secretId, secretKey)
COSCredentials cred = new BasicCOSCredentials("你的secretId", "你的secretKey");
// 2 設(shè)置bucket的區(qū)域, COS地域的簡(jiǎn)稱(chēng)請(qǐng)參照 https://cloud.tencent.com/document/product/436/6224
ClientConfig clientConfig = new ClientConfig(new Region("ap-nanjing"));
// 3 生成 cos 客戶(hù)端
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");
// 生成預(yù)簽名上傳 URL
URL url = cosclient.generatePresignedUrl(bucketName, key, expirationTime, HttpMethodName.PUT, new HashMap<>(), new HashMap<>());
return url.toString();
}
postman發(fā)送請(qǐng)求獲取簽名鏈接:文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-657428.html
postman拿著簽名上傳鏈接,上傳文件二進(jìn)制流(如果用表單上傳,請(qǐng)求方法是post,還要帶上"key:文件名",與"Content-Type:image/jpeg"才能成功上傳)
PUT上傳
點(diǎn)擊上傳后查看上傳結(jié)果:
獲取請(qǐng)求訪(fǎng)問(wèn)地址拼接就不寫(xiě)了,之前寫(xiě)過(guò),更多原理可以問(wèn)我,或者看上一篇關(guān)于阿里云的博客文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-657428.html
到了這里,關(guān)于騰訊云COS云對(duì)象存儲(chǔ),分布式解決簽名上傳的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!