cos-wx-sdk-v5 1.7.0 → 1.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
9
9
 
10
+ ## [v1.7.0](https://github.com/tencentyun/cos-wx-sdk-v5/compare/v1.6.2...v1.7.0) - 2024-05-24
11
+
12
+ feat
13
+ - getObject 新增对 Key 校验
14
+
15
+ ### Merged
16
+
17
+ - feat: 1.7.0 [`#103`](https://github.com/tencentyun/cos-wx-sdk-v5/pull/103)
18
+
19
+ ### Commits
20
+
21
+ - Updated CHANGELOG.md [`8c61b5d`](https://github.com/tencentyun/cos-wx-sdk-v5/commit/8c61b5dc4d38bbe7e9aab0c28748a67a4e61c05b)
22
+
10
23
  ## [v1.6.2](https://github.com/tencentyun/cos-wx-sdk-v5/compare/v1.6.1...v1.6.2) - 2024-04-16
11
24
 
12
25
  feat
@@ -415,8 +428,6 @@ fix:CIHost兼容处理
415
428
 
416
429
  ## [v1.0.13](https://github.com/tencentyun/cos-wx-sdk-v5/compare/v1.0.12...v1.0.13) - 2021-11-11
417
430
 
418
- fix:修复uploadSliceItem
419
-
420
431
  ### Commits
421
432
 
422
433
  - Updated CHANGELOG.md [`6c52c38`](https://github.com/tencentyun/cos-wx-sdk-v5/commit/6c52c382a2e5ff5edf346fb94869b67097f6f9dc)
package/README.md CHANGED
@@ -26,29 +26,37 @@ var Bucket = 'test-1250000000';
26
26
  var Region = 'ap-guangzhou';
27
27
 
28
28
  // 初始化实例
29
- var cos = new COS({
29
+ const cos = new COS({
30
+ SimpleUploadMethod: 'putObject', // 强烈建议,高级上传、批量上传内部对小文件做简单上传时使用putObject,sdk版本至少需要v1.3.0
30
31
  getAuthorization: function (options, callback) {
31
- // 异步获取签名
32
+ // 初始化时不会调用,只有调用 cos 方法(例如 cos.putObject)时才会进入
33
+ // 异步获取临时密钥
32
34
  wx.request({
33
- url: 'https://example.com/sts.php', // 步骤二提供的签名接口
35
+ url: 'https://example.com/server/sts.php',
34
36
  data: {
35
- Method: options.Method,
36
- Key: options.Key
37
+ bucket: options.Bucket,
38
+ region: options.Region,
37
39
  },
38
- dataType: 'text',
40
+ dataType: 'json',
39
41
  success: function (result) {
40
- var data = result.data;
42
+ const data = result.data;
43
+ const credentials = data && data.credentials;
44
+ if (!data || !credentials) return console.error('credentials invalid');
41
45
  callback({
42
- TmpSecretId: data.credentials && data.credentials.tmpSecretId,
43
- TmpSecretKey: data.credentials && data.credentials.tmpSecretKey,
44
- XCosSecurityToken: data.credentials && data.credentials.sessionToken,
45
- ExpiredTime: data.expiredTime,
46
+ TmpSecretId: credentials.tmpSecretId,
47
+ TmpSecretKey: credentials.tmpSecretKey,
48
+ // v1.2.0之前版本的 SDK 使用 XCosSecurityToken 而不是 SecurityToken
49
+ SecurityToken: credentials.sessionToken,
50
+ // 建议返回服务器时间作为签名的开始时间,避免用户浏览器本地时间偏差过大导致签名错误
51
+ StartTime: data.startTime, // 时间戳,单位秒,如:1580000000
52
+ ExpiredTime: data.expiredTime, // 时间戳,单位秒,如:1580000900
46
53
  });
47
54
  }
48
55
  });
49
56
  }
50
57
  });
51
58
 
59
+
52
60
  // 选择文件
53
61
  wx.chooseImage({
54
62
  count: 1, // 默认9
@@ -71,7 +71,7 @@ function getSnapshot() {
71
71
  },
72
72
  function (err, data) {
73
73
  if (err) {
74
- console.log('请求出错');
74
+ console.log(err);
75
75
  } else {
76
76
  const imgBase64 = wx.arrayBufferToBase64(data.Body);
77
77
  console.log(imgBase64);