Hysen Labs
Library / SDK
tencentyun/cos-js-sdk-v4 avatar
tencentyun

cos-js-sdk-v4

腾讯云 COS JS SDK(JSON API)

50 stars31 forksJavaScriptMIT
01
DEEP OPEN-SOURCE ANALYSIS

cos-js-sdk-v4: Tencent COS from the browser

Tencent Cloud's COS JavaScript SDK built on the JSON API, where v4 requires a region, splits out its own signing, and folds multipart uploads into a single call.

02
DEEP OPEN-SOURCE ANALYSIS

What it is and what you need

cos-js-sdk-v4 is the Tencent Cloud COS JavaScript SDK based on the JSON API. The preparation steps require an HTML5-capable browser, and the appid, bucket, secret id, and secret key obtained from the COS console. The README also covers configuring cross-origin settings for the bucket you plan to access, with a sample origin value to follow.

03
DEEP OPEN-SOURCE ANALYSIS

What v4 changed

Version 3 had no region information, while v4 requires a region at initialization, with codes like gz for South China, sh for East China, and tj for North China. Signing also changed: v3's auth.php was tightly coupled and computed the sha1 with Flash, whereas v4 separates the signing logic so you can implement getAppSign and getAppSignOnce yourself, and it ships a complete browser-side signing example. One gotcha is that the signature passed to the SDK should be URL encoded.

04
DEEP OPEN-SOURCE ANALYSIS

Uploads and extras

Upload became simpler. v3 split normal upload and multipart upload into separate interfaces, while v4 exposes a single upload call that automatically falls into multipart logic for large files, though manual multipart is still possible. v4 also adds an onprogress callback and modular packaging that can be built with gulp.

05
DEEP OPEN-SOURCE ANALYSIS

Picking a version

The README answers the obvious question of which SDK to use. Log into the COS console and look at the top-left label: if it reads Cloud Object Storage v4, use the v4 SDK, otherwise stick with v3. It is the kind of decision note that saves real confusion downstream.

06
DEEP OPEN-SOURCE ANALYSIS

Editorial conclusion

The v4 changes boil down to region-aware initialization, separate signing logic, one upload path, and a progress callback, with the console deciding which SDK version you need.

07
DEEP OPEN-SOURCE ANALYSIS

Official sources

08
Community notes

Community notes