cos-wx-sdk-v5 1.4.4 → 1.4.5
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 +13 -0
- package/demo/config.js +3 -3
- package/demo/demo-no-sdk.js +49 -1
- package/demo/lib/cos-wx-sdk-v5.js +2 -2
- package/demo/lib/cos-wx-sdk-v5.min.js +1 -1
- package/demo/project.config.json +1 -1
- package/demo-album/lib/cos-wx-sdk-v5.js +2 -2
- package/demo-album/lib/cos-wx-sdk-v5.min.js +1 -1
- package/package.json +1 -1
- package/src/util.js +1 -1
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.4.4](https://github.com/tencentyun/cos-wx-sdk-v5/compare/v1.4.3...v1.4.4) - 2022-10-20
|
|
11
|
+
|
|
12
|
+
- 分块复制支持续传
|
|
13
|
+
- 合法域名校验支持内网域名和.cn域名
|
|
14
|
+
|
|
15
|
+
### Merged
|
|
16
|
+
|
|
17
|
+
- feat1.4.4 [`#77`](https://github.com/tencentyun/cos-wx-sdk-v5/pull/77)
|
|
18
|
+
|
|
19
|
+
### Commits
|
|
20
|
+
|
|
21
|
+
- Updated CHANGELOG.md [`cdf8af6`](https://github.com/tencentyun/cos-wx-sdk-v5/commit/cdf8af65f6b44ae1ed8244655073b6e3003535a0)
|
|
22
|
+
|
|
10
23
|
## [v1.4.3](https://github.com/tencentyun/cos-wx-sdk-v5/compare/v1.4.2...v1.4.3) - 2022-09-22
|
|
11
24
|
|
|
12
25
|
feat
|
package/demo/config.js
CHANGED
package/demo/demo-no-sdk.js
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
var CosAuth = require('./lib/cos-auth');
|
|
2
2
|
var config = require('./config');
|
|
3
3
|
|
|
4
|
+
var ForcePathStyle = true;
|
|
4
5
|
var uploadFile = function () {
|
|
5
6
|
// 请求用到的参数
|
|
6
7
|
// var prefix = 'https://cos.' + config.Region + '.myqcloud.com/' + config.Bucket + '/'; // 这个是后缀式,签名也要指定 Pathname: '/' + config.Bucket + '/'
|
|
7
8
|
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
|
+
}
|
|
8
13
|
|
|
9
14
|
// 对更多字符编码的 url encode 格式
|
|
10
15
|
var camSafeUrlEncode = function (str) {
|
|
@@ -93,13 +98,56 @@ var uploadFile = function () {
|
|
|
93
98
|
});
|
|
94
99
|
};
|
|
95
100
|
|
|
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
|
+
|
|
96
144
|
// 选择文件
|
|
97
145
|
wx.chooseImage({
|
|
98
146
|
count: 1, // 默认9
|
|
99
147
|
sizeType: ['original'], // 可以指定是原图还是压缩图,这里默认用原图
|
|
100
148
|
sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
|
|
101
149
|
success: function (res) {
|
|
102
|
-
|
|
150
|
+
putFile(res.tempFiles[0].path);
|
|
103
151
|
}
|
|
104
152
|
})
|
|
105
153
|
};
|
|
@@ -6450,7 +6450,7 @@ module.exports = function(module) {
|
|
|
6450
6450
|
/*! exports provided: name, version, description, main, scripts, repository, author, license, dependencies, devDependencies, default */
|
|
6451
6451
|
/***/ (function(module) {
|
|
6452
6452
|
|
|
6453
|
-
module.exports = JSON.parse("{\"name\":\"cos-wx-sdk-v5\",\"version\":\"1.4.
|
|
6453
|
+
module.exports = JSON.parse("{\"name\":\"cos-wx-sdk-v5\",\"version\":\"1.4.5\",\"description\":\"小程序 SDK for [腾讯云对象存储服务](https://cloud.tencent.com/product/cos)\",\"main\":\"demo/lib/cos-wx-sdk-v5.min.js\",\"scripts\":{\"dev\":\"cross-env NODE_ENV=development node build.js --mode=development\",\"build\":\"cross-env NODE_ENV=production node build.js --mode=production\",\"sts.js\":\"node server/sts.js\"},\"repository\":{\"type\":\"git\",\"url\":\"http://github.com/tencentyun/cos-wx-sdk-v5.git\"},\"author\":\"carsonxu\",\"license\":\"ISC\",\"dependencies\":{\"mime\":\"^2.4.6\",\"@xmldom/xmldom\":\"^0.8.2\"},\"devDependencies\":{\"babel-core\":\"6.26.3\",\"babel-loader\":\"8.2.5\",\"@babel/preset-env\":\"7.16.11\",\"body-parser\":\"^1.18.3\",\"cross-env\":\"^7.0.3\",\"express\":\"^4.17.1\",\"qcloud-cos-sts\":\"^3.0.2\",\"terser-webpack-plugin\":\"4.2.3\",\"webpack\":\"4.46.0\",\"webpack-cli\":\"4.10.0\"}}");
|
|
6454
6454
|
|
|
6455
6455
|
/***/ }),
|
|
6456
6456
|
|
|
@@ -13649,7 +13649,7 @@ var apiWrapper = function apiWrapper(apiName, apiFn) {
|
|
|
13649
13649
|
};
|
|
13650
13650
|
|
|
13651
13651
|
var errMsg = checkParams();
|
|
13652
|
-
var isSync =
|
|
13652
|
+
var isSync = ['getAuth', 'getObjectUrl'].includes(apiName);
|
|
13653
13653
|
var Promise = global.Promise;
|
|
13654
13654
|
|
|
13655
13655
|
if (!isSync && Promise && !callback) {
|