cos-wx-sdk-v5 1.4.5 → 1.4.7
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 +26 -0
- package/demo/config.js +3 -3
- package/demo/demo-no-sdk.js +1 -49
- package/demo/lib/cos-wx-sdk-v5.js +580 -208
- package/demo/lib/cos-wx-sdk-v5.min.js +2 -2
- package/demo/project.config.json +1 -1
- package/demo-album/lib/cos-wx-sdk-v5.js +580 -208
- package/demo-album/lib/cos-wx-sdk-v5.min.js +2 -2
- package/package.json +3 -3
- package/src/advance.js +77 -71
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,32 @@ 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.4.6](https://github.com/tencentyun/cos-wx-sdk-v5/compare/v1.4.5...v1.4.6) - 2022-10-25
|
|
11
|
+
|
|
12
|
+
fix
|
|
13
|
+
- 修复批量上传uploadFiles偶现问题
|
|
14
|
+
|
|
15
|
+
### Merged
|
|
16
|
+
|
|
17
|
+
- fix: 修复批量上传偶现异常问题 [`#79`](https://github.com/tencentyun/cos-wx-sdk-v5/pull/79)
|
|
18
|
+
|
|
19
|
+
### Commits
|
|
20
|
+
|
|
21
|
+
- Updated CHANGELOG.md [`7e3717b`](https://github.com/tencentyun/cos-wx-sdk-v5/commit/7e3717b05835873f465c70aa6ceac96c5b5e76ea)
|
|
22
|
+
|
|
23
|
+
## [v1.4.5](https://github.com/tencentyun/cos-wx-sdk-v5/compare/v1.4.4...v1.4.5) - 2022-10-22
|
|
24
|
+
|
|
25
|
+
fix
|
|
26
|
+
- getObjectUrl暂时只支持回调写法
|
|
27
|
+
|
|
28
|
+
### Merged
|
|
29
|
+
|
|
30
|
+
- fix: getObjectUrl暂时只支持回调写法 [`#78`](https://github.com/tencentyun/cos-wx-sdk-v5/pull/78)
|
|
31
|
+
|
|
32
|
+
### Commits
|
|
33
|
+
|
|
34
|
+
- Updated CHANGELOG.md [`8cc1986`](https://github.com/tencentyun/cos-wx-sdk-v5/commit/8cc19868dac5683cd807cfb8678c74c477b29ce5)
|
|
35
|
+
|
|
10
36
|
## [v1.4.4](https://github.com/tencentyun/cos-wx-sdk-v5/compare/v1.4.3...v1.4.4) - 2022-10-20
|
|
11
37
|
|
|
12
38
|
- 分块复制支持续传
|
package/demo/config.js
CHANGED
package/demo/demo-no-sdk.js
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
var CosAuth = require('./lib/cos-auth');
|
|
2
2
|
var config = require('./config');
|
|
3
3
|
|
|
4
|
-
var ForcePathStyle = true;
|
|
5
4
|
var uploadFile = function () {
|
|
6
5
|
// 请求用到的参数
|
|
7
6
|
// var prefix = 'https://cos.' + config.Region + '.myqcloud.com/' + config.Bucket + '/'; // 这个是后缀式,签名也要指定 Pathname: '/' + config.Bucket + '/'
|
|
8
7
|
var prefix = 'https://' + config.Bucket + '.cos.' + config.Region + '.myqcloud.com/';
|
|
9
|
-
if (ForcePathStyle) {
|
|
10
|
-
// 后缀式请求在签名时域名使用地域域名,而不是存储桶域名,具体说明见本文上述“3.后缀式请求”
|
|
11
|
-
prefix = 'https://cos.' + config.Region + '.myqcloud.com/' + config.Bucket + '/';
|
|
12
|
-
}
|
|
13
8
|
|
|
14
9
|
// 对更多字符编码的 url encode 格式
|
|
15
10
|
var camSafeUrlEncode = function (str) {
|
|
@@ -98,56 +93,13 @@ var uploadFile = function () {
|
|
|
98
93
|
});
|
|
99
94
|
};
|
|
100
95
|
|
|
101
|
-
var putFile = function (filePath) {
|
|
102
|
-
var Key = filePath.substr(filePath.lastIndexOf('/') + 1); // 这里指定上传的文件名
|
|
103
|
-
var signPathname = '/' + Key; // PutObject 接口 Key 是放在 url 传输,所以请求路径和签名路径是 /Key
|
|
104
|
-
if (ForcePathStyle) {
|
|
105
|
-
// 后缀式请求在签名时用的路径,要包含存储桶名称,具体说明见本文上述“3.后缀式请求”
|
|
106
|
-
signPathname = '/' + config.Bucket + '/' + Key;
|
|
107
|
-
}
|
|
108
|
-
getAuthorization({Method: 'PUT', Pathname: signPathname}, function (AuthData) {
|
|
109
|
-
// 需要从文件临时路径读取出文件内容
|
|
110
|
-
var wxfs = wx.getFileSystemManager();
|
|
111
|
-
wxfs.readFile({
|
|
112
|
-
filePath: filePath,
|
|
113
|
-
success: function (fileRes) {
|
|
114
|
-
var requestTask = wx.request({
|
|
115
|
-
url: prefix + signPathname.substr(signPathname.lastIndexOf('/') + 1),
|
|
116
|
-
method: 'PUT',
|
|
117
|
-
header: {
|
|
118
|
-
'Authorization': AuthData.Authorization,
|
|
119
|
-
'x-cos-security-token': AuthData.XCosSecurityToken,
|
|
120
|
-
},
|
|
121
|
-
data: fileRes.data,
|
|
122
|
-
success: function success(res) {
|
|
123
|
-
var url = prefix + camSafeUrlEncode(Key).replace(/%2F/g, '/');
|
|
124
|
-
if (res.statusCode === 200) {
|
|
125
|
-
wx.showModal({title: '上传成功', content: url, showCancel: false});
|
|
126
|
-
} else {
|
|
127
|
-
wx.showModal({title: '上传失败', content: JSON.stringify(response), showCancel: false});
|
|
128
|
-
}
|
|
129
|
-
console.log(res.statusCode);
|
|
130
|
-
console.log(url);
|
|
131
|
-
},
|
|
132
|
-
fail: function fail(response) {
|
|
133
|
-
wx.showModal({title: '上传失败', content: JSON.stringify(response), showCancel: false});
|
|
134
|
-
},
|
|
135
|
-
});
|
|
136
|
-
requestTask.onProgressUpdate(function (res) {
|
|
137
|
-
console.log('正在进度:', res);
|
|
138
|
-
});
|
|
139
|
-
},
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
};
|
|
143
|
-
|
|
144
96
|
// 选择文件
|
|
145
97
|
wx.chooseImage({
|
|
146
98
|
count: 1, // 默认9
|
|
147
99
|
sizeType: ['original'], // 可以指定是原图还是压缩图,这里默认用原图
|
|
148
100
|
sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
|
|
149
101
|
success: function (res) {
|
|
150
|
-
|
|
102
|
+
uploadFile(res.tempFiles[0].path);
|
|
151
103
|
}
|
|
152
104
|
})
|
|
153
105
|
};
|