-
Notifications
You must be signed in to change notification settings - Fork 58
/
delete_object.js
72 lines (63 loc) · 2.25 KB
/
delete_object.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
var COS = require('../lib/cos-wx-sdk-v5');
var cos = new COS({
// ForcePathStyle: true, // 如果使用了很多存储桶,可以通过打开后缀式,减少配置白名单域名数量,请求时会用地域域名
getAuthorization: function (options, callback) {
// 异步获取临时密钥
wx.request({
url: 'https://example.com/server/sts.php',
data: {
bucket: options.Bucket,
region: options.Region,
},
dataType: 'json',
success: function (result) {
var data = result.data;
var credentials = data && data.credentials;
if (!data || !credentials) return console.error('credentials invalid');
callback({
TmpSecretId: credentials.tmpSecretId,
TmpSecretKey: credentials.tmpSecretKey,
XCosSecurityToken: credentials.sessionToken,
// 建议返回服务器时间作为签名的开始时间,避免用户浏览器本地时间偏差过大导致签名错误
StartTime: data.startTime, // 时间戳,单位秒,如:1580000000
ExpiredTime: data.expiredTime, // 时间戳,单位秒,如:1580000900
});
}
});
}
});
// 删除对象
function deleteObject() {
//.cssg-snippet-body-start:[delete-object]
cos.deleteObject({
Bucket: 'examplebucket-1250000000', /* 必须 */
Region: 'ap-beijing', /* 必须 */
Key: 'picture.jpg' /* 必须 */
}, function(err, data) {
console.log(err || data);
});
//.cssg-snippet-body-end
}
// 删除多个对象
function deleteMultiObject() {
//.cssg-snippet-body-start:[delete-multi-object]
cos.deleteMultipleObject({
Bucket: 'examplebucket-1250000000', /* 必须 */
Region: 'ap-beijing', /* 必须 */
Objects: [
{Key: 'picture.jpg'},
{Key: '2.zip'},
]
}, function(err, data) {
console.log(err || data);
});
//.cssg-snippet-body-end
}
//.cssg-methods-pragma
function callDeleteObject() {
// 删除对象
deleteObject()
// 删除多个对象
deleteMultiObject()
//.cssg-methods-pragma
}