@nocobase/plugin-file-manager 2.1.0-beta.32 → 2.1.0-beta.33
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/dist/client-v2/450.f590b4c220108742.js +10 -0
- package/dist/client-v2/index.d.ts +1 -0
- package/dist/client-v2/index.js +1 -1
- package/dist/externalVersion.js +10 -12
- package/dist/node_modules/@aws-sdk/client-s3/package.json +1 -1
- package/dist/node_modules/@aws-sdk/lib-storage/package.json +1 -1
- package/dist/node_modules/ali-oss/package.json +1 -1
- package/dist/node_modules/cos-nodejs-sdk-v5/.github/workflows/auto-changelog.yml +55 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/.prettierrc +10 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/.travis.yml +16 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/LICENSE +21 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/demo/crc64.js +9 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/demo/demo-sts-scope.js +75 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/demo/demo-sts.js +65 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/demo/demo.js +4542 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/demo/util.js +135 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/index.d.ts +2610 -0
- package/dist/node_modules/{multer-cos → cos-nodejs-sdk-v5}/index.js +2 -2
- package/dist/node_modules/cos-nodejs-sdk-v5/package.json +1 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/sdk/advance.js +1659 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/sdk/async.js +59 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/sdk/base.js +4404 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/sdk/cos.js +137 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/sdk/event.js +34 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/sdk/select-stream.js +181 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/sdk/session.js +126 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/sdk/task.js +255 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/sdk/util.js +776 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/test/csp.js +1302 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/test/test.js +6119 -0
- package/dist/node_modules/mime-match/package.json +1 -1
- package/dist/node_modules/mime-types/package.json +1 -1
- package/dist/node_modules/mkdirp/package.json +1 -1
- package/dist/node_modules/url-join/package.json +1 -1
- package/dist/server/storages/tx-cos.d.ts +16 -1
- package/dist/server/storages/tx-cos.js +111 -10
- package/package.json +2 -3
- package/dist/client/StorageOptions.d.ts +0 -10
- package/dist/client-v2/450.24143827c94b9dca.js +0 -10
- package/dist/client-v2/501.37bff0473d880acd.js +0 -10
- package/dist/client-v2/885.b832814bff4497c8.js +0 -10
- package/dist/node_modules/multer-cos/LICENSE +0 -24
- package/dist/node_modules/multer-cos/demo/index.js +0 -39
- package/dist/node_modules/multer-cos/demo/myMulter.js +0 -88
- package/dist/node_modules/multer-cos/package.json +0 -1
|
@@ -0,0 +1,4542 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
var fs = require('fs');
|
|
3
|
+
var path = require('path');
|
|
4
|
+
var util = require('./util');
|
|
5
|
+
var COS = require('../index');
|
|
6
|
+
var pathLib = require('path');
|
|
7
|
+
var config = require('./config');
|
|
8
|
+
var json2xml = require('../sdk/util').json2xml;
|
|
9
|
+
|
|
10
|
+
var cos = new COS({
|
|
11
|
+
// 必选参数
|
|
12
|
+
SecretId: config.SecretId,
|
|
13
|
+
SecretKey: config.SecretKey,
|
|
14
|
+
// 可选参数
|
|
15
|
+
FileParallelLimit: 3, // 控制文件上传并发数
|
|
16
|
+
ChunkParallelLimit: 8, // 控制单个文件下分片上传并发数,在同园区上传可以设置较大的并发数
|
|
17
|
+
ChunkSize: 1024 * 1024 * 8, // 控制分片大小,单位 B,在同园区上传可以设置较大的分片大小
|
|
18
|
+
Proxy: '',
|
|
19
|
+
Protocol: 'https:',
|
|
20
|
+
FollowRedirect: false,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
var TaskId;
|
|
24
|
+
|
|
25
|
+
function camSafeUrlEncode(str) {
|
|
26
|
+
return encodeURIComponent(str)
|
|
27
|
+
.replace(/!/g, '%21')
|
|
28
|
+
.replace(/'/g, '%27')
|
|
29
|
+
.replace(/\(/g, '%28')
|
|
30
|
+
.replace(/\)/g, '%29')
|
|
31
|
+
.replace(/\*/g, '%2A');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function getAuth() {
|
|
35
|
+
var key = '1mb.zip';
|
|
36
|
+
var auth = cos.getAuth({
|
|
37
|
+
Method: 'get',
|
|
38
|
+
Key: key,
|
|
39
|
+
Expires: 60,
|
|
40
|
+
});
|
|
41
|
+
// 注意:这里的 Bucket 格式是 test-1250000000
|
|
42
|
+
console.log(
|
|
43
|
+
'http://' +
|
|
44
|
+
config.Bucket +
|
|
45
|
+
'.cos.' +
|
|
46
|
+
config.Region +
|
|
47
|
+
'.myqcloud.com' +
|
|
48
|
+
'/' +
|
|
49
|
+
camSafeUrlEncode(key).replace(/%2F/g, '/') +
|
|
50
|
+
'?sign=' +
|
|
51
|
+
encodeURIComponent(auth)
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function getV4Auth() {
|
|
56
|
+
console.log();
|
|
57
|
+
var key = '中文.txt';
|
|
58
|
+
var auth = cos.getV4Auth({
|
|
59
|
+
Bucket: config.Bucket,
|
|
60
|
+
Key: key,
|
|
61
|
+
Expires: 60,
|
|
62
|
+
});
|
|
63
|
+
// 注意:这里的 Bucket 格式是 test-1250000000
|
|
64
|
+
console.log(
|
|
65
|
+
'http://' +
|
|
66
|
+
config.Bucket +
|
|
67
|
+
'.cos.' +
|
|
68
|
+
config.Region +
|
|
69
|
+
'.myqcloud.com' +
|
|
70
|
+
'/' +
|
|
71
|
+
camSafeUrlEncode(key).replace(/%2F/g, '/') +
|
|
72
|
+
'?sign=' +
|
|
73
|
+
encodeURIComponent(auth)
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function getObjectUrl() {
|
|
78
|
+
var url = cos.getObjectUrl(
|
|
79
|
+
{
|
|
80
|
+
Bucket: config.Bucket,
|
|
81
|
+
Region: config.Region,
|
|
82
|
+
Key: '1mb.zip',
|
|
83
|
+
Expires: 60,
|
|
84
|
+
Sign: true,
|
|
85
|
+
},
|
|
86
|
+
function (err, data) {
|
|
87
|
+
console.log(err || data);
|
|
88
|
+
}
|
|
89
|
+
);
|
|
90
|
+
console.log(url);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function getService() {
|
|
94
|
+
cos.getService(
|
|
95
|
+
{
|
|
96
|
+
Region: 'ap-guangzhou',
|
|
97
|
+
},
|
|
98
|
+
function (err, data) {
|
|
99
|
+
console.log(err || data);
|
|
100
|
+
}
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function putBucket() {
|
|
105
|
+
cos.putBucket(
|
|
106
|
+
{
|
|
107
|
+
Bucket: 'testnew-' + config.Bucket.substr(config.Bucket.lastIndexOf('-') + 1),
|
|
108
|
+
Region: 'ap-guangzhou',
|
|
109
|
+
// BucketAZConfig: 'MAZ',
|
|
110
|
+
// BucketArchConfig: 'OFS',
|
|
111
|
+
},
|
|
112
|
+
function (err, data) {
|
|
113
|
+
console.log(err || data);
|
|
114
|
+
}
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function getBucket() {
|
|
119
|
+
cos.getBucket(
|
|
120
|
+
{
|
|
121
|
+
Bucket: config.Bucket,
|
|
122
|
+
Region: config.Region,
|
|
123
|
+
},
|
|
124
|
+
function (err, data) {
|
|
125
|
+
console.log(err || data);
|
|
126
|
+
}
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function headBucket() {
|
|
131
|
+
cos.headBucket(
|
|
132
|
+
{
|
|
133
|
+
Bucket: config.Bucket,
|
|
134
|
+
Region: config.Region,
|
|
135
|
+
},
|
|
136
|
+
function (err, data) {
|
|
137
|
+
console.log(err || data);
|
|
138
|
+
}
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function deleteBucket() {
|
|
143
|
+
cos.deleteBucket(
|
|
144
|
+
{
|
|
145
|
+
Bucket: 'testnew-' + config.Bucket.substr(config.Bucket.lastIndexOf('-') + 1),
|
|
146
|
+
Region: 'ap-guangzhou',
|
|
147
|
+
},
|
|
148
|
+
function (err, data) {
|
|
149
|
+
console.log(err || data);
|
|
150
|
+
}
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function putBucketAcl() {
|
|
155
|
+
cos.putBucketAcl(
|
|
156
|
+
{
|
|
157
|
+
Bucket: config.Bucket,
|
|
158
|
+
Region: config.Region,
|
|
159
|
+
// GrantFullControl: 'id="qcs::cam::uin/1001:uin/1001",id="qcs::cam::uin/1002:uin/1002"',
|
|
160
|
+
// GrantWrite: 'id="qcs::cam::uin/1001:uin/1001",id="qcs::cam::uin/1002:uin/1002"',
|
|
161
|
+
// GrantRead: 'id="qcs::cam::uin/1001:uin/1001",id="qcs::cam::uin/1002:uin/1002"',
|
|
162
|
+
// GrantReadAcp: 'id="qcs::cam::uin/1001:uin/1001",id="qcs::cam::uin/1002:uin/1002"',
|
|
163
|
+
// GrantWriteAcp: 'id="qcs::cam::uin/1001:uin/1001",id="qcs::cam::uin/1002:uin/1002"',
|
|
164
|
+
// ACL: 'public-read-write',
|
|
165
|
+
// ACL: 'public-read',
|
|
166
|
+
ACL: 'private',
|
|
167
|
+
AccessControlPolicy: {
|
|
168
|
+
Owner: {
|
|
169
|
+
// AccessControlPolicy 里必须有 owner
|
|
170
|
+
ID: 'qcs::cam::uin/10001:uin/10001', // 10001 是 Bucket 所属用户的 QQ 号
|
|
171
|
+
},
|
|
172
|
+
Grants: [
|
|
173
|
+
{
|
|
174
|
+
Grantee: {
|
|
175
|
+
URI: 'http://cam.qcloud.com/groups/global/AllUsers', // 允许匿名用户组访问
|
|
176
|
+
},
|
|
177
|
+
Permission: 'READ',
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
Grantee: {
|
|
181
|
+
ID: 'qcs::cam::uin/1001:uin/1001', // 10002 是 QQ 号
|
|
182
|
+
},
|
|
183
|
+
Permission: 'WRITE',
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
Grantee: {
|
|
187
|
+
ID: 'qcs::cam::uin/10002:uin/10002', // 10002 是 QQ 号
|
|
188
|
+
},
|
|
189
|
+
Permission: 'READ_ACP',
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
Grantee: {
|
|
193
|
+
ID: 'qcs::cam::uin/10002:uin/10002', // 10002 是 QQ 号
|
|
194
|
+
},
|
|
195
|
+
Permission: 'WRITE_ACP',
|
|
196
|
+
},
|
|
197
|
+
],
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
function (err, data) {
|
|
201
|
+
console.log(err || data);
|
|
202
|
+
}
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function getBucketAcl() {
|
|
207
|
+
cos.getBucketAcl(
|
|
208
|
+
{
|
|
209
|
+
Bucket: config.Bucket,
|
|
210
|
+
Region: config.Region,
|
|
211
|
+
},
|
|
212
|
+
function (err, data) {
|
|
213
|
+
console.log(err || data);
|
|
214
|
+
}
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function putBucketCors() {
|
|
219
|
+
cos.putBucketCors(
|
|
220
|
+
{
|
|
221
|
+
Bucket: config.Bucket,
|
|
222
|
+
Region: config.Region,
|
|
223
|
+
ResponseVary: 'true',
|
|
224
|
+
CORSRules: [
|
|
225
|
+
{
|
|
226
|
+
AllowedOrigin: ['*'],
|
|
227
|
+
AllowedMethod: ['GET', 'POST', 'PUT', 'DELETE', 'HEAD'],
|
|
228
|
+
AllowedHeader: ['*'],
|
|
229
|
+
ExposeHeader: [
|
|
230
|
+
'ETag',
|
|
231
|
+
'Date',
|
|
232
|
+
'Content-Length',
|
|
233
|
+
'x-cos-acl',
|
|
234
|
+
'x-cos-version-id',
|
|
235
|
+
'x-cos-request-id',
|
|
236
|
+
'x-cos-delete-marker',
|
|
237
|
+
'x-cos-server-side-encryption',
|
|
238
|
+
],
|
|
239
|
+
MaxAgeSeconds: 5,
|
|
240
|
+
},
|
|
241
|
+
],
|
|
242
|
+
},
|
|
243
|
+
function (err, data) {
|
|
244
|
+
console.log(err || data);
|
|
245
|
+
}
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function getBucketCors() {
|
|
250
|
+
cos.getBucketCors(
|
|
251
|
+
{
|
|
252
|
+
Bucket: config.Bucket,
|
|
253
|
+
Region: config.Region,
|
|
254
|
+
},
|
|
255
|
+
function (err, data) {
|
|
256
|
+
console.log(err || data);
|
|
257
|
+
}
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function deleteBucketCors() {
|
|
262
|
+
cos.deleteBucketCors(
|
|
263
|
+
{
|
|
264
|
+
Bucket: config.Bucket,
|
|
265
|
+
Region: config.Region,
|
|
266
|
+
},
|
|
267
|
+
function (err, data) {
|
|
268
|
+
console.log(err || data);
|
|
269
|
+
}
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function putBucketPolicy() {
|
|
274
|
+
var AppId = config.Bucket.substr(config.Bucket.lastIndexOf('-') + 1);
|
|
275
|
+
cos.putBucketPolicy(
|
|
276
|
+
{
|
|
277
|
+
Policy: {
|
|
278
|
+
version: '2.0',
|
|
279
|
+
statement: [
|
|
280
|
+
{
|
|
281
|
+
effect: 'allow',
|
|
282
|
+
principal: { qcs: ['qcs::cam::uin/10001:uin/10001'] }, // 这里的 10001 是 QQ 号
|
|
283
|
+
action: [
|
|
284
|
+
// 这里可以从临时密钥的权限上控制前端允许的操作
|
|
285
|
+
// 'name/cos:*', // 这样写可以包含下面所有权限
|
|
286
|
+
|
|
287
|
+
// // 列出所有允许的操作
|
|
288
|
+
// // ACL 读写
|
|
289
|
+
// 'name/cos:GetBucketACL',
|
|
290
|
+
// 'name/cos:PutBucketACL',
|
|
291
|
+
// 'name/cos:GetObjectACL',
|
|
292
|
+
// 'name/cos:PutObjectACL',
|
|
293
|
+
// // 简单 Bucket 操作
|
|
294
|
+
// 'name/cos:PutBucket',
|
|
295
|
+
// 'name/cos:HeadBucket',
|
|
296
|
+
// 'name/cos:GetBucket',
|
|
297
|
+
// 'name/cos:DeleteBucket',
|
|
298
|
+
// 'name/cos:GetBucketLocation',
|
|
299
|
+
// // Versioning
|
|
300
|
+
// 'name/cos:PutBucketVersioning',
|
|
301
|
+
// 'name/cos:GetBucketVersioning',
|
|
302
|
+
// // CORS
|
|
303
|
+
// 'name/cos:PutBucketCORS',
|
|
304
|
+
// 'name/cos:GetBucketCORS',
|
|
305
|
+
// 'name/cos:DeleteBucketCORS',
|
|
306
|
+
// // Lifecycle
|
|
307
|
+
// 'name/cos:PutBucketLifecycle',
|
|
308
|
+
// 'name/cos:GetBucketLifecycle',
|
|
309
|
+
// 'name/cos:DeleteBucketLifecycle',
|
|
310
|
+
// // Replication
|
|
311
|
+
// 'name/cos:PutBucketReplication',
|
|
312
|
+
// 'name/cos:GetBucketReplication',
|
|
313
|
+
// 'name/cos:DeleteBucketReplication',
|
|
314
|
+
// // 删除文件
|
|
315
|
+
// 'name/cos:DeleteMultipleObject',
|
|
316
|
+
// 'name/cos:DeleteObject',
|
|
317
|
+
// 简单文件操作
|
|
318
|
+
'name/cos:PutObject',
|
|
319
|
+
'name/cos:AppendObject',
|
|
320
|
+
'name/cos:GetObject',
|
|
321
|
+
'name/cos:HeadObject',
|
|
322
|
+
'name/cos:OptionsObject',
|
|
323
|
+
'name/cos:PutObjectCopy',
|
|
324
|
+
'name/cos:PostObjectRestore',
|
|
325
|
+
// 分片上传操作
|
|
326
|
+
'name/cos:InitiateMultipartUpload',
|
|
327
|
+
'name/cos:ListMultipartUploads',
|
|
328
|
+
'name/cos:ListParts',
|
|
329
|
+
'name/cos:UploadPart',
|
|
330
|
+
'name/cos:CompleteMultipartUpload',
|
|
331
|
+
'name/cos:AbortMultipartUpload',
|
|
332
|
+
],
|
|
333
|
+
// "resource": ["qcs::cos:ap-guangzhou:uid/1250000000:test-1250000000/*"] // 1250000000 是 appid
|
|
334
|
+
resource: ['qcs::cos:' + config.Region + ':uid/' + AppId + ':' + config.Bucket + '/*'], // 1250000000 是 appid
|
|
335
|
+
},
|
|
336
|
+
],
|
|
337
|
+
},
|
|
338
|
+
Bucket: config.Bucket,
|
|
339
|
+
Region: config.Region,
|
|
340
|
+
},
|
|
341
|
+
function (err, data) {
|
|
342
|
+
console.log(err || data);
|
|
343
|
+
}
|
|
344
|
+
);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
function getBucketPolicy() {
|
|
348
|
+
cos.getBucketPolicy(
|
|
349
|
+
{
|
|
350
|
+
Bucket: config.Bucket,
|
|
351
|
+
Region: config.Region,
|
|
352
|
+
},
|
|
353
|
+
function (err, data) {
|
|
354
|
+
console.log(err || data);
|
|
355
|
+
}
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
function deleteBucketPolicy() {
|
|
360
|
+
cos.deleteBucketPolicy(
|
|
361
|
+
{
|
|
362
|
+
Bucket: config.Bucket,
|
|
363
|
+
Region: config.Region,
|
|
364
|
+
},
|
|
365
|
+
function (err, data) {
|
|
366
|
+
console.log(err || data);
|
|
367
|
+
}
|
|
368
|
+
);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
function getBucketLocation() {
|
|
372
|
+
cos.getBucketLocation(
|
|
373
|
+
{
|
|
374
|
+
Bucket: config.Bucket,
|
|
375
|
+
Region: config.Region,
|
|
376
|
+
},
|
|
377
|
+
function (err, data) {
|
|
378
|
+
console.log(err || data);
|
|
379
|
+
}
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
function putBucketTagging() {
|
|
384
|
+
cos.putBucketTagging(
|
|
385
|
+
{
|
|
386
|
+
Bucket: config.Bucket,
|
|
387
|
+
Region: config.Region,
|
|
388
|
+
Tags: [
|
|
389
|
+
{ Key: 'k1', Value: 'v1' },
|
|
390
|
+
{ Key: 'k2', Value: 'v2' },
|
|
391
|
+
],
|
|
392
|
+
},
|
|
393
|
+
function (err, data) {
|
|
394
|
+
console.log(err || data);
|
|
395
|
+
}
|
|
396
|
+
);
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
function getBucketTagging() {
|
|
400
|
+
cos.getBucketTagging(
|
|
401
|
+
{
|
|
402
|
+
Bucket: config.Bucket,
|
|
403
|
+
Region: config.Region,
|
|
404
|
+
},
|
|
405
|
+
function (err, data) {
|
|
406
|
+
console.log(err || data);
|
|
407
|
+
}
|
|
408
|
+
);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
function deleteBucketTagging() {
|
|
412
|
+
cos.deleteBucketTagging(
|
|
413
|
+
{
|
|
414
|
+
Bucket: config.Bucket,
|
|
415
|
+
Region: config.Region,
|
|
416
|
+
},
|
|
417
|
+
function (err, data) {
|
|
418
|
+
console.log(err || data);
|
|
419
|
+
}
|
|
420
|
+
);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
function putBucketLifecycle() {
|
|
424
|
+
cos.putBucketLifecycle(
|
|
425
|
+
{
|
|
426
|
+
Bucket: config.Bucket,
|
|
427
|
+
Region: config.Region,
|
|
428
|
+
Rules: [
|
|
429
|
+
{
|
|
430
|
+
ID: '1',
|
|
431
|
+
Status: 'Enabled',
|
|
432
|
+
Filter: {},
|
|
433
|
+
Transition: {
|
|
434
|
+
Days: '30',
|
|
435
|
+
StorageClass: 'STANDARD_IA',
|
|
436
|
+
},
|
|
437
|
+
},
|
|
438
|
+
{
|
|
439
|
+
ID: '2',
|
|
440
|
+
Status: 'Enabled',
|
|
441
|
+
Filter: {
|
|
442
|
+
Prefix: 'dir/',
|
|
443
|
+
},
|
|
444
|
+
Transition: {
|
|
445
|
+
Days: '180',
|
|
446
|
+
StorageClass: 'ARCHIVE',
|
|
447
|
+
},
|
|
448
|
+
},
|
|
449
|
+
{
|
|
450
|
+
ID: '3',
|
|
451
|
+
Status: 'Enabled',
|
|
452
|
+
Filter: {},
|
|
453
|
+
Expiration: {
|
|
454
|
+
Days: '180',
|
|
455
|
+
},
|
|
456
|
+
},
|
|
457
|
+
{
|
|
458
|
+
ID: '4',
|
|
459
|
+
Status: 'Enabled',
|
|
460
|
+
Filter: {},
|
|
461
|
+
AbortIncompleteMultipartUpload: {
|
|
462
|
+
DaysAfterInitiation: '30',
|
|
463
|
+
},
|
|
464
|
+
},
|
|
465
|
+
],
|
|
466
|
+
},
|
|
467
|
+
function (err, data) {
|
|
468
|
+
console.log(err || data);
|
|
469
|
+
}
|
|
470
|
+
);
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
function getBucketLifecycle() {
|
|
474
|
+
cos.getBucketLifecycle(
|
|
475
|
+
{
|
|
476
|
+
Bucket: config.Bucket,
|
|
477
|
+
Region: config.Region,
|
|
478
|
+
},
|
|
479
|
+
function (err, data) {
|
|
480
|
+
console.log(err || data);
|
|
481
|
+
}
|
|
482
|
+
);
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
function deleteBucketLifecycle() {
|
|
486
|
+
cos.deleteBucketLifecycle(
|
|
487
|
+
{
|
|
488
|
+
Bucket: config.Bucket,
|
|
489
|
+
Region: config.Region,
|
|
490
|
+
},
|
|
491
|
+
function (err, data) {
|
|
492
|
+
console.log(err || data);
|
|
493
|
+
}
|
|
494
|
+
);
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
function putBucketVersioning() {
|
|
498
|
+
cos.putBucketVersioning(
|
|
499
|
+
{
|
|
500
|
+
Bucket: config.Bucket,
|
|
501
|
+
Region: config.Region,
|
|
502
|
+
VersioningConfiguration: {
|
|
503
|
+
Status: 'Enabled',
|
|
504
|
+
},
|
|
505
|
+
},
|
|
506
|
+
function (err, data) {
|
|
507
|
+
console.log(err || data);
|
|
508
|
+
}
|
|
509
|
+
);
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
function getBucketVersioning() {
|
|
513
|
+
cos.getBucketVersioning(
|
|
514
|
+
{
|
|
515
|
+
Bucket: config.Bucket,
|
|
516
|
+
Region: config.Region,
|
|
517
|
+
},
|
|
518
|
+
function (err, data) {
|
|
519
|
+
console.log(err || data);
|
|
520
|
+
}
|
|
521
|
+
);
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
function putBucketReplication() {
|
|
525
|
+
var AppId = config.Bucket.substr(config.Bucket.lastIndexOf('-') + 1);
|
|
526
|
+
cos.putBucketReplication(
|
|
527
|
+
{
|
|
528
|
+
Bucket: config.Bucket,
|
|
529
|
+
Region: config.Region,
|
|
530
|
+
ReplicationConfiguration: {
|
|
531
|
+
Role: 'qcs::cam::uin/10001:uin/10001',
|
|
532
|
+
Rules: [
|
|
533
|
+
{
|
|
534
|
+
ID: '1',
|
|
535
|
+
Status: 'Enabled',
|
|
536
|
+
Prefix: 'sync/',
|
|
537
|
+
Destination: {
|
|
538
|
+
Bucket: 'qcs:id/0:cos:ap-chengdu:appid/' + AppId + ':backup',
|
|
539
|
+
// StorageClass: "Standard",
|
|
540
|
+
},
|
|
541
|
+
},
|
|
542
|
+
],
|
|
543
|
+
},
|
|
544
|
+
},
|
|
545
|
+
function (err, data) {
|
|
546
|
+
console.log(err || data);
|
|
547
|
+
}
|
|
548
|
+
);
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
function getBucketReplication() {
|
|
552
|
+
cos.getBucketReplication(
|
|
553
|
+
{
|
|
554
|
+
Bucket: config.Bucket,
|
|
555
|
+
Region: config.Region,
|
|
556
|
+
},
|
|
557
|
+
function (err, data) {
|
|
558
|
+
console.log(err || data);
|
|
559
|
+
}
|
|
560
|
+
);
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
function deleteBucketReplication() {
|
|
564
|
+
cos.deleteBucketReplication(
|
|
565
|
+
{
|
|
566
|
+
Bucket: config.Bucket,
|
|
567
|
+
Region: config.Region,
|
|
568
|
+
},
|
|
569
|
+
function (err, data) {
|
|
570
|
+
console.log(err || data);
|
|
571
|
+
}
|
|
572
|
+
);
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
function putBucketWebsite() {
|
|
576
|
+
cos.putBucketWebsite(
|
|
577
|
+
{
|
|
578
|
+
Bucket: config.Bucket,
|
|
579
|
+
Region: config.Region,
|
|
580
|
+
WebsiteConfiguration: {
|
|
581
|
+
IndexDocument: {
|
|
582
|
+
Suffix: 'index.html', // 必选
|
|
583
|
+
},
|
|
584
|
+
RedirectAllRequestsTo: {
|
|
585
|
+
Protocol: 'https',
|
|
586
|
+
},
|
|
587
|
+
// ErrorDocument: {
|
|
588
|
+
// Key: "error.html"
|
|
589
|
+
// },
|
|
590
|
+
// RoutingRules: [{
|
|
591
|
+
// Condition: {
|
|
592
|
+
// HttpErrorCodeReturnedEquals: "404"
|
|
593
|
+
// },
|
|
594
|
+
// Redirect: {
|
|
595
|
+
// Protocol: "https",
|
|
596
|
+
// ReplaceKeyWith: "404.html"
|
|
597
|
+
// }
|
|
598
|
+
// }, {
|
|
599
|
+
// Condition: {
|
|
600
|
+
// KeyPrefixEquals: "docs/"
|
|
601
|
+
// },
|
|
602
|
+
// Redirect: {
|
|
603
|
+
// Protocol: "https",
|
|
604
|
+
// ReplaceKeyPrefixWith: "documents/"
|
|
605
|
+
// }
|
|
606
|
+
// }, {
|
|
607
|
+
// Condition: {
|
|
608
|
+
// KeyPrefixEquals: "img/"
|
|
609
|
+
// },
|
|
610
|
+
// Redirect: {
|
|
611
|
+
// Protocol: "https",
|
|
612
|
+
// ReplaceKeyWith: "picture.jpg"
|
|
613
|
+
// }
|
|
614
|
+
// }]
|
|
615
|
+
},
|
|
616
|
+
},
|
|
617
|
+
function (err, data) {
|
|
618
|
+
console.log(err || data);
|
|
619
|
+
}
|
|
620
|
+
);
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
function getBucketWebsite() {
|
|
624
|
+
cos.getBucketWebsite(
|
|
625
|
+
{
|
|
626
|
+
Bucket: config.Bucket,
|
|
627
|
+
Region: config.Region,
|
|
628
|
+
},
|
|
629
|
+
function (err, data) {
|
|
630
|
+
console.log(err || data);
|
|
631
|
+
}
|
|
632
|
+
);
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
function deleteBucketWebsite() {
|
|
636
|
+
cos.deleteBucketWebsite(
|
|
637
|
+
{
|
|
638
|
+
Bucket: config.Bucket,
|
|
639
|
+
Region: config.Region,
|
|
640
|
+
},
|
|
641
|
+
function (err, data) {
|
|
642
|
+
console.log(err || data);
|
|
643
|
+
}
|
|
644
|
+
);
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
function putBucketReferer() {
|
|
648
|
+
cos.putBucketReferer(
|
|
649
|
+
{
|
|
650
|
+
Bucket: config.Bucket,
|
|
651
|
+
Region: config.Region,
|
|
652
|
+
RefererConfiguration: {
|
|
653
|
+
Status: 'Enabled',
|
|
654
|
+
RefererType: 'White-List',
|
|
655
|
+
DomainList: {
|
|
656
|
+
Domains: ['*.qq.com', '*.qcloud.com'],
|
|
657
|
+
},
|
|
658
|
+
EmptyReferConfiguration: 'Allow',
|
|
659
|
+
},
|
|
660
|
+
},
|
|
661
|
+
function (err, data) {
|
|
662
|
+
console.log(err || data);
|
|
663
|
+
}
|
|
664
|
+
);
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
function getBucketReferer() {
|
|
668
|
+
cos.getBucketReferer(
|
|
669
|
+
{
|
|
670
|
+
Bucket: config.Bucket,
|
|
671
|
+
Region: config.Region,
|
|
672
|
+
},
|
|
673
|
+
function (err, data) {
|
|
674
|
+
console.log(err || JSON.stringify(data, null, ' '));
|
|
675
|
+
}
|
|
676
|
+
);
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
function putBucketDomain() {
|
|
680
|
+
cos.putBucketDomain(
|
|
681
|
+
{
|
|
682
|
+
Bucket: config.Bucket,
|
|
683
|
+
Region: config.Region,
|
|
684
|
+
DomainRule: [
|
|
685
|
+
{
|
|
686
|
+
Status: 'DISABLED',
|
|
687
|
+
Name: 'www.testDomain1.com',
|
|
688
|
+
Type: 'REST',
|
|
689
|
+
},
|
|
690
|
+
{
|
|
691
|
+
Status: 'DISABLED',
|
|
692
|
+
Name: 'www.testDomain2.com',
|
|
693
|
+
Type: 'WEBSITE',
|
|
694
|
+
},
|
|
695
|
+
],
|
|
696
|
+
},
|
|
697
|
+
function (err, data) {
|
|
698
|
+
console.log(err || data);
|
|
699
|
+
}
|
|
700
|
+
);
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
function getBucketDomain() {
|
|
704
|
+
cos.getBucketDomain(
|
|
705
|
+
{
|
|
706
|
+
Bucket: config.Bucket,
|
|
707
|
+
Region: config.Region,
|
|
708
|
+
},
|
|
709
|
+
function (err, data) {
|
|
710
|
+
console.log(err || data);
|
|
711
|
+
}
|
|
712
|
+
);
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
function deleteBucketDomain() {
|
|
716
|
+
cos.deleteBucketDomain(
|
|
717
|
+
{
|
|
718
|
+
Bucket: config.Bucket,
|
|
719
|
+
Region: config.Region,
|
|
720
|
+
},
|
|
721
|
+
function (err, data) {
|
|
722
|
+
console.log(err || data);
|
|
723
|
+
}
|
|
724
|
+
);
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
function putBucketOrigin() {
|
|
728
|
+
cos.putBucketOrigin(
|
|
729
|
+
{
|
|
730
|
+
Bucket: config.Bucket,
|
|
731
|
+
Region: config.Region,
|
|
732
|
+
OriginRule: [
|
|
733
|
+
{
|
|
734
|
+
OriginType: 'Mirror',
|
|
735
|
+
OriginCondition: { HTTPStatusCode: 404, Prefix: '' },
|
|
736
|
+
OriginParameter: {
|
|
737
|
+
Protocol: 'HTTP',
|
|
738
|
+
FollowQueryString: 'true',
|
|
739
|
+
HttpHeader: {
|
|
740
|
+
NewHttpHeader: {
|
|
741
|
+
Header: [
|
|
742
|
+
{
|
|
743
|
+
Key: 'a',
|
|
744
|
+
Value: 'a',
|
|
745
|
+
},
|
|
746
|
+
],
|
|
747
|
+
},
|
|
748
|
+
},
|
|
749
|
+
FollowRedirection: 'true',
|
|
750
|
+
HttpRedirectCode: ['301', '302'],
|
|
751
|
+
},
|
|
752
|
+
OriginInfo: {
|
|
753
|
+
HostInfo: { HostName: 'qq.com' },
|
|
754
|
+
FileInfo: {
|
|
755
|
+
PrefixConfiguration: { Prefix: '123/' },
|
|
756
|
+
SuffixConfiguration: { Suffix: '.jpg' },
|
|
757
|
+
},
|
|
758
|
+
},
|
|
759
|
+
RulePriority: 1,
|
|
760
|
+
},
|
|
761
|
+
],
|
|
762
|
+
},
|
|
763
|
+
function (err, data) {
|
|
764
|
+
console.log(err || data);
|
|
765
|
+
}
|
|
766
|
+
);
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
function getBucketOrigin() {
|
|
770
|
+
cos.getBucketOrigin(
|
|
771
|
+
{
|
|
772
|
+
Bucket: config.Bucket,
|
|
773
|
+
Region: config.Region,
|
|
774
|
+
},
|
|
775
|
+
function (err, data) {
|
|
776
|
+
console.log(err || data);
|
|
777
|
+
}
|
|
778
|
+
);
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
function deleteBucketOrigin() {
|
|
782
|
+
cos.deleteBucketOrigin(
|
|
783
|
+
{
|
|
784
|
+
Bucket: config.Bucket,
|
|
785
|
+
Region: config.Region,
|
|
786
|
+
},
|
|
787
|
+
function (err, data) {
|
|
788
|
+
console.log(err || data);
|
|
789
|
+
}
|
|
790
|
+
);
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
function putBucketLogging() {
|
|
794
|
+
var AppId = config.Bucket.substr(config.Bucket.lastIndexOf('-') + 1);
|
|
795
|
+
cos.putBucketLogging(
|
|
796
|
+
{
|
|
797
|
+
Bucket: config.Bucket,
|
|
798
|
+
Region: config.Region,
|
|
799
|
+
BucketLoggingStatus: {
|
|
800
|
+
LoggingEnabled: {
|
|
801
|
+
TargetBucket: 'bucket-logging-' + AppId,
|
|
802
|
+
TargetPrefix: 'logging',
|
|
803
|
+
},
|
|
804
|
+
},
|
|
805
|
+
},
|
|
806
|
+
function (err, data) {
|
|
807
|
+
console.log(err || data);
|
|
808
|
+
}
|
|
809
|
+
);
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
function getBucketLogging() {
|
|
813
|
+
cos.getBucketLogging(
|
|
814
|
+
{
|
|
815
|
+
Bucket: config.Bucket,
|
|
816
|
+
Region: config.Region,
|
|
817
|
+
},
|
|
818
|
+
function (err, data) {
|
|
819
|
+
console.log(err || data);
|
|
820
|
+
}
|
|
821
|
+
);
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
function deleteBucketLogging() {
|
|
825
|
+
cos.putBucketLogging(
|
|
826
|
+
{
|
|
827
|
+
Bucket: config.Bucket,
|
|
828
|
+
Region: config.Region,
|
|
829
|
+
BucketLoggingStatus: {},
|
|
830
|
+
},
|
|
831
|
+
function (err, data) {
|
|
832
|
+
console.log(err || data);
|
|
833
|
+
}
|
|
834
|
+
);
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
function putBucketInventory() {
|
|
838
|
+
var AppId = config.Bucket.substr(config.Bucket.lastIndexOf('-') + 1);
|
|
839
|
+
cos.putBucketInventory(
|
|
840
|
+
{
|
|
841
|
+
Bucket: config.Bucket,
|
|
842
|
+
Region: config.Region,
|
|
843
|
+
Id: 'inventory_test',
|
|
844
|
+
InventoryConfiguration: {
|
|
845
|
+
Id: 'inventory_test',
|
|
846
|
+
IsEnabled: 'true',
|
|
847
|
+
Destination: {
|
|
848
|
+
COSBucketDestination: {
|
|
849
|
+
Format: 'CSV',
|
|
850
|
+
AccountId: config.Uin,
|
|
851
|
+
Bucket: 'qcs::cos:ap-guangzhou::bucket-logging-' + AppId,
|
|
852
|
+
Prefix: 'inventory',
|
|
853
|
+
Encryption: {
|
|
854
|
+
SSECOS: '',
|
|
855
|
+
},
|
|
856
|
+
},
|
|
857
|
+
},
|
|
858
|
+
Schedule: {
|
|
859
|
+
Frequency: 'Daily',
|
|
860
|
+
},
|
|
861
|
+
Filter: {
|
|
862
|
+
Prefix: 'myPrefix',
|
|
863
|
+
},
|
|
864
|
+
IncludedObjectVersions: 'All',
|
|
865
|
+
OptionalFields: [
|
|
866
|
+
'Size',
|
|
867
|
+
'LastModifiedDate',
|
|
868
|
+
'ETag',
|
|
869
|
+
'StorageClass',
|
|
870
|
+
'IsMultipartUploaded',
|
|
871
|
+
'ReplicationStatus',
|
|
872
|
+
],
|
|
873
|
+
},
|
|
874
|
+
},
|
|
875
|
+
function (err, data) {
|
|
876
|
+
console.log(err || data);
|
|
877
|
+
}
|
|
878
|
+
);
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
function getBucketInventory() {
|
|
882
|
+
cos.getBucketInventory(
|
|
883
|
+
{
|
|
884
|
+
Bucket: config.Bucket,
|
|
885
|
+
Region: config.Region,
|
|
886
|
+
Id: 'inventory_test',
|
|
887
|
+
},
|
|
888
|
+
function (err, data) {
|
|
889
|
+
console.log(err || JSON.stringify(data));
|
|
890
|
+
}
|
|
891
|
+
);
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
function deleteBucketInventory() {
|
|
895
|
+
cos.deleteBucketInventory(
|
|
896
|
+
{
|
|
897
|
+
Bucket: config.Bucket,
|
|
898
|
+
Region: config.Region,
|
|
899
|
+
Id: 'inventory_test',
|
|
900
|
+
},
|
|
901
|
+
function (err, data) {
|
|
902
|
+
console.log(err || JSON.stringify(data));
|
|
903
|
+
}
|
|
904
|
+
);
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
function listBucketInventory() {
|
|
908
|
+
cos.listBucketInventory(
|
|
909
|
+
{
|
|
910
|
+
Bucket: config.Bucket,
|
|
911
|
+
Region: config.Region,
|
|
912
|
+
},
|
|
913
|
+
function (err, data) {
|
|
914
|
+
console.log(err || JSON.stringify(data));
|
|
915
|
+
}
|
|
916
|
+
);
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
function putBucketAccelerate() {
|
|
920
|
+
cos.putBucketAccelerate(
|
|
921
|
+
{
|
|
922
|
+
Bucket: config.Bucket,
|
|
923
|
+
Region: config.Region,
|
|
924
|
+
AccelerateConfiguration: {
|
|
925
|
+
Status: 'Enabled',
|
|
926
|
+
},
|
|
927
|
+
},
|
|
928
|
+
function (err, data) {
|
|
929
|
+
console.log(err || data);
|
|
930
|
+
}
|
|
931
|
+
);
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
function getBucketAccelerate() {
|
|
935
|
+
cos.getBucketAccelerate(
|
|
936
|
+
{
|
|
937
|
+
Bucket: config.Bucket,
|
|
938
|
+
Region: config.Region,
|
|
939
|
+
},
|
|
940
|
+
function (err, data) {
|
|
941
|
+
console.log(err || data);
|
|
942
|
+
}
|
|
943
|
+
);
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
function putBucketEncryption() {
|
|
947
|
+
cos.putBucketEncryption(
|
|
948
|
+
{
|
|
949
|
+
Bucket: config.Bucket,
|
|
950
|
+
Region: config.Region,
|
|
951
|
+
ServerSideEncryptionConfiguration: {
|
|
952
|
+
Rule: [
|
|
953
|
+
{
|
|
954
|
+
ApplySideEncryptionConfiguration: {
|
|
955
|
+
SSEAlgorithm: 'AES256',
|
|
956
|
+
},
|
|
957
|
+
},
|
|
958
|
+
],
|
|
959
|
+
},
|
|
960
|
+
},
|
|
961
|
+
function (err, data) {
|
|
962
|
+
console.log(JSON.stringify(err || data, null, 2));
|
|
963
|
+
}
|
|
964
|
+
);
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
function getBucketEncryption() {
|
|
968
|
+
cos.getBucketEncryption(
|
|
969
|
+
{
|
|
970
|
+
Bucket: config.Bucket,
|
|
971
|
+
Region: config.Region,
|
|
972
|
+
},
|
|
973
|
+
function (err, data) {
|
|
974
|
+
console.log(err || JSON.stringify(data));
|
|
975
|
+
}
|
|
976
|
+
);
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
function deleteBucketEncryption() {
|
|
980
|
+
cos.deleteBucketEncryption(
|
|
981
|
+
{
|
|
982
|
+
Bucket: config.Bucket,
|
|
983
|
+
Region: config.Region,
|
|
984
|
+
},
|
|
985
|
+
function (err, data) {
|
|
986
|
+
console.log(err || JSON.stringify(data));
|
|
987
|
+
}
|
|
988
|
+
);
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
function putObject() {
|
|
992
|
+
// 创建测试文件
|
|
993
|
+
var filename = '1mb.zip';
|
|
994
|
+
var filepath = path.resolve(__dirname, filename);
|
|
995
|
+
util.createFile(filepath, 1024 * 1024, function (err) {
|
|
996
|
+
// 调用方法
|
|
997
|
+
cos.putObject(
|
|
998
|
+
{
|
|
999
|
+
Bucket: config.Bucket /* 必须 */,
|
|
1000
|
+
Region: config.Region,
|
|
1001
|
+
Key: filename /* 必须 */,
|
|
1002
|
+
onTaskReady: function (tid) {
|
|
1003
|
+
TaskId = tid;
|
|
1004
|
+
},
|
|
1005
|
+
onProgress: function (progressData) {
|
|
1006
|
+
console.log(JSON.stringify(progressData));
|
|
1007
|
+
},
|
|
1008
|
+
// 格式1. 传入文件内容
|
|
1009
|
+
// Body: fs.readFileSync(filepath),
|
|
1010
|
+
// 格式2. 传入文件流,必须需要传文件大小
|
|
1011
|
+
Body: fs.createReadStream(filepath),
|
|
1012
|
+
ContentLength: fs.statSync(filepath).size,
|
|
1013
|
+
Headers: {
|
|
1014
|
+
// 万象持久化接口,上传时持久化
|
|
1015
|
+
// 'Pic-Operations': '{"is_pic_info": 1, "rules": [{"fileid": "test.jpg", "rule": "imageMogr2/thumbnail/!50p"}]}'
|
|
1016
|
+
},
|
|
1017
|
+
},
|
|
1018
|
+
function (err, data) {
|
|
1019
|
+
console.log(err || data);
|
|
1020
|
+
fs.unlinkSync(filepath);
|
|
1021
|
+
}
|
|
1022
|
+
);
|
|
1023
|
+
});
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
function putObject_base64ToBuffer() {
|
|
1027
|
+
// 创建测试文件
|
|
1028
|
+
var filename = 'test.png';
|
|
1029
|
+
var filepath = path.resolve(__dirname, filename);
|
|
1030
|
+
var base64Url =
|
|
1031
|
+
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAABRFBMVEUAAAAAo/8Ao/8Ao/8Ao/8ApP8Aov8Ao/8Abv8Abv8AyNwAyNwAo/8Ao/8Ao/8Abv8Ao/8AivgAo/8AyNwAbv8Abv8AydwApf8Abf8Ao/8AbP8Ao/8AyNwAydwAbv8AydwApP8Ao/8AyNwAo/8AyNwAydsAyNwAxd8Aov8AyNwAytsAo/8Abv8AyNwAbv8Av+MAo/8AytsAo/8Abv8AyNwAo/8Abv8AqfkAbv8Aov8Abv8AyNwAov8Abv8Ao/8Abv8Ao/8AydwAo/8Ao/8Ate8Ay9oAvOcAof8AveAAyNwAyNwAo/8AyNwAy9kAo/8AyNwAyNwAo/8AqP8Aaf8AyNwAbv0Abv8Abv8AaP8Ao/8Ao/8Ao/8Ao/8Abv8AyNwAgvcAaP8A0dkAo/8AyNwAav8Abv8Ao/8Abv8AyNwAy9sAvOUAtePdkYxjAAAAZnRSTlMAw/co8uAuJAn8+/Tt29R8DAX77+nZz87Jv6CTh3lxTklAPjouJRsL5tjAuLiyr62roaCakYp0XVtOQTMyLiohICAcGRP49vTv5+PJurawq6mnnJuYl4+OiIB7eXVvX15QSDgqHxNcw3l6AAABe0lEQVQ4y82P11oCQQxGIy5FUJpKk6aAhV6k92LvvXedDfj+92ZkYQHxnnMxu3/OfJMEJo6y++baXf5XVw22GVGcsRmq431mQZRYyIzRGgdXi+HwIv86NDBKisrRAtU1hSj9pkZ9jpo/9YKbRsmNNKCHDXI00BxfMMirKNpMcjQ5Lm4/YZArUXyBYUwg40nsdr5jb3LBe25VWpNeKa1GENsEnq52C80z1uW48estiKjb19G54QdCrScnKAU69U3KJ4jzrsBawDWPuOcBqMyRvlcb1Y+zjMUBVsivAKe4gXgEKiVjSh9wlunGMmwiOqFL3RI0cj+nkgp3jC1BELVFkGiZSuvkp3tZZWZ2sKCuDj185PXqfmwI7AAOUctHkJoOeXg3sxA4ES+l7CVvrYHMEmNp8GtR+wycPG0+1RrwWQUzl4CvgQmPP5Ddofl8tWkJVT7J+BIAaxEktrYZoRAUfXgOGYHfcOqw3WF/EdLccz5cMfvUCPb4QwUmhB8+v12HZPCkbgAAAABJRU5ErkJggg==';
|
|
1032
|
+
var body = Buffer.from(base64Url.split(',')[1], 'base64');
|
|
1033
|
+
util.createFile(filepath, 1024 * 1024, function (err) {
|
|
1034
|
+
// 调用方法
|
|
1035
|
+
cos.putObject(
|
|
1036
|
+
{
|
|
1037
|
+
Bucket: config.Bucket /* 必须 */,
|
|
1038
|
+
Region: config.Region,
|
|
1039
|
+
Key: filename /* 必须 */,
|
|
1040
|
+
onTaskReady: function (tid) {
|
|
1041
|
+
TaskId = tid;
|
|
1042
|
+
},
|
|
1043
|
+
onProgress: function (progressData) {
|
|
1044
|
+
console.log(JSON.stringify(progressData));
|
|
1045
|
+
},
|
|
1046
|
+
// 格式1. 传入文件内容
|
|
1047
|
+
// Body: fs.readFileSync(filepath),
|
|
1048
|
+
// 格式2. 传入文件流,必须需要传文件大小
|
|
1049
|
+
Body: body,
|
|
1050
|
+
ContentLength: body.length,
|
|
1051
|
+
Headers: {
|
|
1052
|
+
// 万象持久化接口,上传时持久化
|
|
1053
|
+
// 'Pic-Operations': '{"is_pic_info": 1, "rules": [{"fileid": "test.jpg", "rule": "imageMogr2/thumbnail/!50p"}]}'
|
|
1054
|
+
},
|
|
1055
|
+
},
|
|
1056
|
+
function (err, data) {
|
|
1057
|
+
console.log(err || data);
|
|
1058
|
+
fs.unlinkSync(filepath);
|
|
1059
|
+
}
|
|
1060
|
+
);
|
|
1061
|
+
});
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
function putObjectCopy() {
|
|
1065
|
+
cos.putObjectCopy(
|
|
1066
|
+
{
|
|
1067
|
+
Bucket: config.Bucket,
|
|
1068
|
+
Region: config.Region,
|
|
1069
|
+
Key: '1mb.copy.zip',
|
|
1070
|
+
CopySource:
|
|
1071
|
+
config.Bucket + '.cos.' + config.Region + '.myqcloud.com/' + camSafeUrlEncode('1mb.zip').replace(/%2F/g, '/'),
|
|
1072
|
+
},
|
|
1073
|
+
function (err, data) {
|
|
1074
|
+
console.log(err || data);
|
|
1075
|
+
}
|
|
1076
|
+
);
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
function getObject() {
|
|
1080
|
+
var filepath1 = path.resolve(__dirname, '1mb.out1.zip');
|
|
1081
|
+
var filepath2 = path.resolve(__dirname, '1mb.out2.zip');
|
|
1082
|
+
var filepath3 = path.resolve(__dirname, '1mb.out3.zip');
|
|
1083
|
+
|
|
1084
|
+
// file1 获取对象字节到内存变量
|
|
1085
|
+
cos.getObject(
|
|
1086
|
+
{
|
|
1087
|
+
Bucket: config.Bucket,
|
|
1088
|
+
Region: config.Region,
|
|
1089
|
+
Key: '1mb.zip',
|
|
1090
|
+
onProgress: function (progressData) {
|
|
1091
|
+
console.log(JSON.stringify(progressData));
|
|
1092
|
+
},
|
|
1093
|
+
},
|
|
1094
|
+
function (err, data) {
|
|
1095
|
+
if (data) {
|
|
1096
|
+
fs.writeFileSync(filepath1, data.Body);
|
|
1097
|
+
} else {
|
|
1098
|
+
console.log(err);
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
);
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
function headObject() {
|
|
1105
|
+
cos.headObject(
|
|
1106
|
+
{
|
|
1107
|
+
Bucket: config.Bucket,
|
|
1108
|
+
Region: config.Region,
|
|
1109
|
+
Key: '1mb.zip',
|
|
1110
|
+
},
|
|
1111
|
+
function (err, data) {
|
|
1112
|
+
console.log(err || data);
|
|
1113
|
+
}
|
|
1114
|
+
);
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
function listObjectVersions() {
|
|
1118
|
+
cos.listObjectVersions(
|
|
1119
|
+
{
|
|
1120
|
+
Bucket: config.Bucket,
|
|
1121
|
+
Region: config.Region,
|
|
1122
|
+
// Prefix: "",
|
|
1123
|
+
// Delimiter: '/'
|
|
1124
|
+
},
|
|
1125
|
+
function (err, data) {
|
|
1126
|
+
console.log(err || JSON.stringify(data, null, ' '));
|
|
1127
|
+
}
|
|
1128
|
+
);
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
function putObjectAcl() {
|
|
1132
|
+
cos.putObjectAcl(
|
|
1133
|
+
{
|
|
1134
|
+
Bucket: config.Bucket,
|
|
1135
|
+
Region: config.Region,
|
|
1136
|
+
Key: '1mb.zip',
|
|
1137
|
+
// GrantFullControl: 'id="qcs::cam::uin/1001:uin/1001",id="qcs::cam::uin/1002:uin/1002"',
|
|
1138
|
+
// GrantWriteAcp: 'id="qcs::cam::uin/1001:uin/1001",id="qcs::cam::uin/1002:uin/1002"',
|
|
1139
|
+
// GrantReadAcp: 'id="qcs::cam::uin/1001:uin/1001",id="qcs::cam::uin/1002:uin/1002"',
|
|
1140
|
+
// GrantRead: 'id="qcs::cam::uin/1001:uin/1001",id="qcs::cam::uin/1002:uin/1002"',
|
|
1141
|
+
// ACL: 'public-read-write',
|
|
1142
|
+
// ACL: 'public-read',
|
|
1143
|
+
// ACL: 'private',
|
|
1144
|
+
ACL: 'default', // 继承上一级目录权限
|
|
1145
|
+
// AccessControlPolicy: {
|
|
1146
|
+
// "Owner": { // AccessControlPolicy 里必须有 owner
|
|
1147
|
+
// "ID": 'qcs::cam::uin/459000000:uin/459000000' // 459000000 是 Bucket 所属用户的 QQ 号
|
|
1148
|
+
// },
|
|
1149
|
+
// "Grants": [{
|
|
1150
|
+
// "Grantee": {
|
|
1151
|
+
// "ID": "qcs::cam::uin/10002:uin/10002", // 10002 是 QQ 号
|
|
1152
|
+
// },
|
|
1153
|
+
// "Permission": "READ"
|
|
1154
|
+
// }]
|
|
1155
|
+
// }
|
|
1156
|
+
},
|
|
1157
|
+
function (err, data) {
|
|
1158
|
+
console.log(err || data);
|
|
1159
|
+
}
|
|
1160
|
+
);
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
function getObjectAcl() {
|
|
1164
|
+
cos.getObjectAcl(
|
|
1165
|
+
{
|
|
1166
|
+
Bucket: config.Bucket,
|
|
1167
|
+
Region: config.Region,
|
|
1168
|
+
Key: '1mb.zip',
|
|
1169
|
+
},
|
|
1170
|
+
function (err, data) {
|
|
1171
|
+
console.log(err || data);
|
|
1172
|
+
}
|
|
1173
|
+
);
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
function deleteObject() {
|
|
1177
|
+
cos.deleteObject(
|
|
1178
|
+
{
|
|
1179
|
+
Bucket: config.Bucket,
|
|
1180
|
+
Region: config.Region,
|
|
1181
|
+
Key: '1mb.zip',
|
|
1182
|
+
},
|
|
1183
|
+
function (err, data) {
|
|
1184
|
+
console.log(err || data);
|
|
1185
|
+
}
|
|
1186
|
+
);
|
|
1187
|
+
}
|
|
1188
|
+
|
|
1189
|
+
function deleteMultipleObject() {
|
|
1190
|
+
cos.deleteMultipleObject(
|
|
1191
|
+
{
|
|
1192
|
+
Bucket: config.Bucket,
|
|
1193
|
+
Region: config.Region,
|
|
1194
|
+
Objects: [{ Key: '中文/中文.txt' }, { Key: '中文/中文.zip', VersionId: 'MTg0NDY3NDI1MzM4NzM0ODA2MTI' }],
|
|
1195
|
+
},
|
|
1196
|
+
function (err, data) {
|
|
1197
|
+
console.log(err || data);
|
|
1198
|
+
}
|
|
1199
|
+
);
|
|
1200
|
+
}
|
|
1201
|
+
|
|
1202
|
+
function restoreObject() {
|
|
1203
|
+
cos.restoreObject(
|
|
1204
|
+
{
|
|
1205
|
+
Bucket: config.Bucket,
|
|
1206
|
+
Region: config.Region,
|
|
1207
|
+
Key: '1.txt',
|
|
1208
|
+
RestoreRequest: {
|
|
1209
|
+
Days: 1,
|
|
1210
|
+
CASJobParameters: {
|
|
1211
|
+
Tier: 'Expedited',
|
|
1212
|
+
},
|
|
1213
|
+
},
|
|
1214
|
+
},
|
|
1215
|
+
function (err, data) {
|
|
1216
|
+
console.log(err || data);
|
|
1217
|
+
}
|
|
1218
|
+
);
|
|
1219
|
+
}
|
|
1220
|
+
|
|
1221
|
+
var selectCsvOpt = {
|
|
1222
|
+
Bucket: config.Bucket,
|
|
1223
|
+
Region: config.Region,
|
|
1224
|
+
Key: '1.csv',
|
|
1225
|
+
SelectType: 2,
|
|
1226
|
+
SelectRequest: {
|
|
1227
|
+
// Expression: "select * from cosobject s limit 100",
|
|
1228
|
+
Expression: 'Select * from COSObject',
|
|
1229
|
+
ExpressionType: 'SQL',
|
|
1230
|
+
InputSerialization: {
|
|
1231
|
+
CSV: {
|
|
1232
|
+
FileHeaderInfo: 'IGNORE',
|
|
1233
|
+
RecordDelimiter: '\\n',
|
|
1234
|
+
FieldDelimiter: ',',
|
|
1235
|
+
QuoteCharacter: '"',
|
|
1236
|
+
QuoteEscapeCharacter: '"',
|
|
1237
|
+
Comments: '#',
|
|
1238
|
+
AllowQuotedRecordDelimiter: 'FALSE',
|
|
1239
|
+
},
|
|
1240
|
+
},
|
|
1241
|
+
OutputSerialization: {
|
|
1242
|
+
CSV: {
|
|
1243
|
+
QuoteFields: 'ASNEEDED',
|
|
1244
|
+
RecordDelimiter: '\\n',
|
|
1245
|
+
FieldDelimiter: ',',
|
|
1246
|
+
QuoteCharacter: '"',
|
|
1247
|
+
QuoteEscapeCharacter: '"',
|
|
1248
|
+
},
|
|
1249
|
+
},
|
|
1250
|
+
RequestProgress: { Enabled: 'FALSE' },
|
|
1251
|
+
},
|
|
1252
|
+
};
|
|
1253
|
+
|
|
1254
|
+
var selectJsonOpt = {
|
|
1255
|
+
Bucket: config.Bucket,
|
|
1256
|
+
Region: config.Region,
|
|
1257
|
+
Key: '1.json',
|
|
1258
|
+
SelectType: 2,
|
|
1259
|
+
SelectRequest: {
|
|
1260
|
+
Expression: 'Select * from COSObject',
|
|
1261
|
+
ExpressionType: 'SQL',
|
|
1262
|
+
InputSerialization: { JSON: { Type: 'DOCUMENT' } },
|
|
1263
|
+
OutputSerialization: { JSON: { RecordDelimiter: '\n' } },
|
|
1264
|
+
RequestProgress: { Enabled: 'FALSE' },
|
|
1265
|
+
},
|
|
1266
|
+
};
|
|
1267
|
+
|
|
1268
|
+
function selectObjectContentStream() {
|
|
1269
|
+
// 查询 JSON
|
|
1270
|
+
var opt = Object.assign(
|
|
1271
|
+
{
|
|
1272
|
+
// DataType: 'raw',
|
|
1273
|
+
},
|
|
1274
|
+
selectJsonOpt
|
|
1275
|
+
);
|
|
1276
|
+
var selectStream = cos.selectObjectContentStream(opt, function (err, data) {
|
|
1277
|
+
console.log(err || data);
|
|
1278
|
+
});
|
|
1279
|
+
var outFile = './result.txt';
|
|
1280
|
+
selectStream.pipe(fs.createWriteStream(outFile));
|
|
1281
|
+
selectStream.on('end', () => console.log(fs.readFileSync(outFile).toString()));
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1284
|
+
function selectObjectContent() {
|
|
1285
|
+
// // 如果返回结果很大,可以用 selectObjectContentStream 处理
|
|
1286
|
+
// // 查询 CSV
|
|
1287
|
+
// cos.selectObjectContent(selectCsvOpt, function (err, data) {
|
|
1288
|
+
// console.log(err || data);
|
|
1289
|
+
// });
|
|
1290
|
+
|
|
1291
|
+
// 查询 JSON
|
|
1292
|
+
cos.selectObjectContent(selectJsonOpt, function (err, data) {
|
|
1293
|
+
console.log(err || data);
|
|
1294
|
+
});
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
function multipartList() {
|
|
1298
|
+
cos.multipartList(
|
|
1299
|
+
{
|
|
1300
|
+
Bucket: config.Bucket,
|
|
1301
|
+
Region: config.Region,
|
|
1302
|
+
Prefix: '',
|
|
1303
|
+
MaxUploads: 1,
|
|
1304
|
+
Delimiter: '/',
|
|
1305
|
+
},
|
|
1306
|
+
function (err, data) {
|
|
1307
|
+
console.log(err || JSON.stringify(data, null, 2));
|
|
1308
|
+
}
|
|
1309
|
+
);
|
|
1310
|
+
}
|
|
1311
|
+
|
|
1312
|
+
function multipartListPart() {
|
|
1313
|
+
cos.multipartListPart(
|
|
1314
|
+
{
|
|
1315
|
+
Bucket: config.Bucket,
|
|
1316
|
+
Region: config.Region,
|
|
1317
|
+
Key: '10mb.zip',
|
|
1318
|
+
MaxParts: 1,
|
|
1319
|
+
UploadId: 'xxx',
|
|
1320
|
+
},
|
|
1321
|
+
function (err, data) {
|
|
1322
|
+
console.log(err || JSON.stringify(data, null, 2));
|
|
1323
|
+
}
|
|
1324
|
+
);
|
|
1325
|
+
}
|
|
1326
|
+
|
|
1327
|
+
function multipartInit() {
|
|
1328
|
+
cos.multipartInit(
|
|
1329
|
+
{
|
|
1330
|
+
Bucket: config.Bucket,
|
|
1331
|
+
Region: config.Region,
|
|
1332
|
+
Key: '10mb.zip',
|
|
1333
|
+
},
|
|
1334
|
+
function (err, data) {
|
|
1335
|
+
console.log(err || JSON.stringify(data, null, 2));
|
|
1336
|
+
}
|
|
1337
|
+
);
|
|
1338
|
+
}
|
|
1339
|
+
|
|
1340
|
+
function multipartUpload() {
|
|
1341
|
+
cos.multipartUpload(
|
|
1342
|
+
{
|
|
1343
|
+
Bucket: config.Bucket,
|
|
1344
|
+
Region: config.Region,
|
|
1345
|
+
Key: '10mb.zip',
|
|
1346
|
+
UploadId: 'xxx',
|
|
1347
|
+
PartNumber: 1,
|
|
1348
|
+
Body: '123',
|
|
1349
|
+
},
|
|
1350
|
+
function (err, data) {
|
|
1351
|
+
console.log(err || JSON.stringify(data, null, 2));
|
|
1352
|
+
}
|
|
1353
|
+
);
|
|
1354
|
+
}
|
|
1355
|
+
|
|
1356
|
+
function multipartCom() {
|
|
1357
|
+
cos.multipartComplete(
|
|
1358
|
+
{
|
|
1359
|
+
Bucket: config.Bucket,
|
|
1360
|
+
Region: config.Region,
|
|
1361
|
+
Key: '1.zip',
|
|
1362
|
+
UploadId: 'xxx',
|
|
1363
|
+
Parts: [
|
|
1364
|
+
{
|
|
1365
|
+
PartNumber: 1,
|
|
1366
|
+
ETag: 'xxx',
|
|
1367
|
+
},
|
|
1368
|
+
],
|
|
1369
|
+
},
|
|
1370
|
+
function (err, data) {
|
|
1371
|
+
console.log(err || JSON.stringify(data, null, 2));
|
|
1372
|
+
}
|
|
1373
|
+
);
|
|
1374
|
+
}
|
|
1375
|
+
|
|
1376
|
+
function multipartAbort() {
|
|
1377
|
+
cos.multipartAbort(
|
|
1378
|
+
{
|
|
1379
|
+
Bucket: config.Bucket,
|
|
1380
|
+
Region: config.Region,
|
|
1381
|
+
Key: '10mb.zip',
|
|
1382
|
+
UploadId: 'xxx',
|
|
1383
|
+
},
|
|
1384
|
+
function (err, data) {
|
|
1385
|
+
console.log(err || JSON.stringify(data, null, 2));
|
|
1386
|
+
}
|
|
1387
|
+
);
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1390
|
+
function abortUploadTask() {
|
|
1391
|
+
cos.abortUploadTask(
|
|
1392
|
+
{
|
|
1393
|
+
Bucket: config.Bucket /* 必须 */,
|
|
1394
|
+
Region: config.Region /* 必须 */,
|
|
1395
|
+
// 格式1,删除单个上传任务
|
|
1396
|
+
// Level: 'task',
|
|
1397
|
+
// Key: '10mb.zip',
|
|
1398
|
+
// UploadId: '14985543913e4e2642e31db217b9a1a3d9b3cd6cf62abfda23372c8d36ffa38585492681e3',
|
|
1399
|
+
// 格式2,删除单个文件所有未完成上传任务
|
|
1400
|
+
Level: 'file',
|
|
1401
|
+
Key: '10mb.zip',
|
|
1402
|
+
// 格式3,删除 Bucket 下所有未完成上传任务
|
|
1403
|
+
// Level: 'bucket',
|
|
1404
|
+
},
|
|
1405
|
+
function (err, data) {
|
|
1406
|
+
console.log(err || data);
|
|
1407
|
+
}
|
|
1408
|
+
);
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1411
|
+
function sliceUploadFile() {
|
|
1412
|
+
// 创建测试文件
|
|
1413
|
+
var filename = '10mb.zip';
|
|
1414
|
+
var filepath = path.resolve(__dirname, filename);
|
|
1415
|
+
util.createFile(filepath, 1024 * 1024 * 10, function (err) {
|
|
1416
|
+
// 调用方法
|
|
1417
|
+
cos.sliceUploadFile(
|
|
1418
|
+
{
|
|
1419
|
+
Bucket: config.Bucket /* 必须 */,
|
|
1420
|
+
Region: config.Region,
|
|
1421
|
+
Key: filename /* 必须 */,
|
|
1422
|
+
FilePath: filepath /* 必须 */,
|
|
1423
|
+
onTaskReady: function (tid) {
|
|
1424
|
+
TaskId = tid;
|
|
1425
|
+
},
|
|
1426
|
+
onHashProgress: function (progressData) {
|
|
1427
|
+
console.log(JSON.stringify(progressData));
|
|
1428
|
+
},
|
|
1429
|
+
onProgress: function (progressData) {
|
|
1430
|
+
console.log(JSON.stringify(progressData));
|
|
1431
|
+
},
|
|
1432
|
+
Headers: {
|
|
1433
|
+
// 万象持久化接口,上传时持久化
|
|
1434
|
+
// 'Pic-Operations': '{"is_pic_info": 1, "rules": [{"fileid": "test.jpg", "rule": "imageMogr2/thumbnail/!50p"}]}'
|
|
1435
|
+
},
|
|
1436
|
+
},
|
|
1437
|
+
function (err, data) {
|
|
1438
|
+
console.log(err || data);
|
|
1439
|
+
fs.unlinkSync(filepath);
|
|
1440
|
+
}
|
|
1441
|
+
);
|
|
1442
|
+
});
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1445
|
+
function cancelTask() {
|
|
1446
|
+
cos.cancelTask(TaskId);
|
|
1447
|
+
console.log('canceled');
|
|
1448
|
+
}
|
|
1449
|
+
|
|
1450
|
+
function pauseTask() {
|
|
1451
|
+
cos.pauseTask(TaskId);
|
|
1452
|
+
console.log('paused');
|
|
1453
|
+
}
|
|
1454
|
+
|
|
1455
|
+
function restartTask() {
|
|
1456
|
+
cos.restartTask(TaskId);
|
|
1457
|
+
console.log('restart');
|
|
1458
|
+
}
|
|
1459
|
+
|
|
1460
|
+
function uploadFile() {
|
|
1461
|
+
var filename = '3mb.zip';
|
|
1462
|
+
var filepath = path.resolve(__dirname, filename);
|
|
1463
|
+
util.createFile(filepath, 1024 * 1024 * 3, function (err) {
|
|
1464
|
+
cos.uploadFile(
|
|
1465
|
+
{
|
|
1466
|
+
Bucket: config.Bucket,
|
|
1467
|
+
Region: config.Region,
|
|
1468
|
+
Key: filename,
|
|
1469
|
+
FilePath: filepath,
|
|
1470
|
+
SliceSize: 1024 * 1024 * 5, // 大于5mb才进行分块上传
|
|
1471
|
+
onProgress: function (info) {
|
|
1472
|
+
var percent = Math.floor(info.percent * 10000) / 100;
|
|
1473
|
+
var speed = Math.floor((info.speed / 1024 / 1024) * 100) / 100;
|
|
1474
|
+
console.log('进度:' + percent + '%; 速度:' + speed + 'Mb/s;');
|
|
1475
|
+
},
|
|
1476
|
+
},
|
|
1477
|
+
function (err, data) {
|
|
1478
|
+
console.log('上传' + (err ? '失败' : '完成'));
|
|
1479
|
+
console.log(err || data);
|
|
1480
|
+
fs.unlinkSync(filepath);
|
|
1481
|
+
}
|
|
1482
|
+
);
|
|
1483
|
+
});
|
|
1484
|
+
}
|
|
1485
|
+
|
|
1486
|
+
function uploadFiles() {
|
|
1487
|
+
var filepath = path.resolve(__dirname, '1mb.zip');
|
|
1488
|
+
util.createFile(filepath, 1024 * 1024 * 10, function (err) {
|
|
1489
|
+
var filename = 'mb.zip';
|
|
1490
|
+
cos.uploadFiles(
|
|
1491
|
+
{
|
|
1492
|
+
files: [
|
|
1493
|
+
{
|
|
1494
|
+
Bucket: config.Bucket,
|
|
1495
|
+
Region: config.Region,
|
|
1496
|
+
Key: '1' + filename,
|
|
1497
|
+
FilePath: filepath,
|
|
1498
|
+
},
|
|
1499
|
+
{
|
|
1500
|
+
Bucket: config.Bucket,
|
|
1501
|
+
Region: config.Region,
|
|
1502
|
+
Key: '2' + filename,
|
|
1503
|
+
FilePath: filepath,
|
|
1504
|
+
// }, {
|
|
1505
|
+
// Bucket: config.Bucket,
|
|
1506
|
+
// Region: config.Region,
|
|
1507
|
+
// Key: '3' + filename,
|
|
1508
|
+
// FilePath: filepath,
|
|
1509
|
+
},
|
|
1510
|
+
],
|
|
1511
|
+
SliceSize: 1024 * 1024,
|
|
1512
|
+
onProgress: function (info) {
|
|
1513
|
+
var percent = Math.floor(info.percent * 10000) / 100;
|
|
1514
|
+
var speed = Math.floor((info.speed / 1024 / 1024) * 100) / 100;
|
|
1515
|
+
console.log('进度:' + percent + '%; 速度:' + speed + 'Mb/s;');
|
|
1516
|
+
},
|
|
1517
|
+
onFileFinish: function (err, data, options) {
|
|
1518
|
+
console.log(options.Key + ' 上传' + (err ? '失败' : '完成'));
|
|
1519
|
+
},
|
|
1520
|
+
},
|
|
1521
|
+
function (err, data) {
|
|
1522
|
+
console.log(err || data);
|
|
1523
|
+
fs.unlinkSync(filepath);
|
|
1524
|
+
}
|
|
1525
|
+
);
|
|
1526
|
+
});
|
|
1527
|
+
}
|
|
1528
|
+
|
|
1529
|
+
function sliceCopyFile() {
|
|
1530
|
+
// 创建测试文件
|
|
1531
|
+
var sourceName = '3mb.zip';
|
|
1532
|
+
var Key = '3mb.copy.zip';
|
|
1533
|
+
|
|
1534
|
+
var sourcePath =
|
|
1535
|
+
config.Bucket + '.cos.' + config.Region + '.myqcloud.com/' + camSafeUrlEncode(sourceName).replace(/%2F/g, '/');
|
|
1536
|
+
|
|
1537
|
+
cos.sliceCopyFile(
|
|
1538
|
+
{
|
|
1539
|
+
Bucket: config.Bucket,
|
|
1540
|
+
Region: config.Region,
|
|
1541
|
+
Key: Key,
|
|
1542
|
+
CopySource: sourcePath,
|
|
1543
|
+
CopySliceSize: 2 * 1024 * 1024, // 大于2M的文件用分片复制,小于则用单片复制
|
|
1544
|
+
onProgress: function (info) {
|
|
1545
|
+
var percent = Math.floor(info.percent * 10000) / 100;
|
|
1546
|
+
var speed = Math.floor((info.speed / 1024 / 1024) * 100) / 100;
|
|
1547
|
+
console.log('进度:' + percent + '%; 速度:' + speed + 'Mb/s;');
|
|
1548
|
+
},
|
|
1549
|
+
},
|
|
1550
|
+
function (err, data) {
|
|
1551
|
+
if (err) {
|
|
1552
|
+
console.log(err);
|
|
1553
|
+
} else {
|
|
1554
|
+
console.log(data);
|
|
1555
|
+
}
|
|
1556
|
+
}
|
|
1557
|
+
);
|
|
1558
|
+
}
|
|
1559
|
+
|
|
1560
|
+
function putObjectTagging() {
|
|
1561
|
+
cos.putObjectTagging(
|
|
1562
|
+
{
|
|
1563
|
+
Bucket: config.Bucket,
|
|
1564
|
+
Region: config.Region,
|
|
1565
|
+
Key: '1mb.zip',
|
|
1566
|
+
Tags: [
|
|
1567
|
+
{ Key: 'k1', Value: 'v1' },
|
|
1568
|
+
{ Key: 'k2', Value: 'v2' },
|
|
1569
|
+
],
|
|
1570
|
+
},
|
|
1571
|
+
function (err, data) {
|
|
1572
|
+
console.log(err || data);
|
|
1573
|
+
}
|
|
1574
|
+
);
|
|
1575
|
+
}
|
|
1576
|
+
|
|
1577
|
+
function getObjectTagging() {
|
|
1578
|
+
cos.getObjectTagging(
|
|
1579
|
+
{
|
|
1580
|
+
Bucket: config.Bucket,
|
|
1581
|
+
Region: config.Region,
|
|
1582
|
+
Key: '1mb.zip',
|
|
1583
|
+
},
|
|
1584
|
+
function (err, data) {
|
|
1585
|
+
console.log(err || data);
|
|
1586
|
+
}
|
|
1587
|
+
);
|
|
1588
|
+
}
|
|
1589
|
+
|
|
1590
|
+
function deleteObjectTagging() {
|
|
1591
|
+
cos.getObjectTagging(
|
|
1592
|
+
{
|
|
1593
|
+
Bucket: config.Bucket,
|
|
1594
|
+
Region: config.Region,
|
|
1595
|
+
Key: '1mb.zip',
|
|
1596
|
+
},
|
|
1597
|
+
function (err, data) {
|
|
1598
|
+
console.log(err || data);
|
|
1599
|
+
}
|
|
1600
|
+
);
|
|
1601
|
+
}
|
|
1602
|
+
|
|
1603
|
+
/* 移动对象*/
|
|
1604
|
+
function moveObject() {
|
|
1605
|
+
// COS 没有对象重命名或移动的接口,移动对象可以通过复制/删除对象实现
|
|
1606
|
+
var source = 'source.txt';
|
|
1607
|
+
var target = 'target.txt';
|
|
1608
|
+
var copySource =
|
|
1609
|
+
config.Bucket + '.cos.' + config.Region + '.myqcloud.com/' + camSafeUrlEncode(source).replace(/%2F/g, '/');
|
|
1610
|
+
cos.putObject(
|
|
1611
|
+
{
|
|
1612
|
+
Bucket: config.Bucket,
|
|
1613
|
+
Region: config.Region,
|
|
1614
|
+
Key: source,
|
|
1615
|
+
Body: 'hello!',
|
|
1616
|
+
},
|
|
1617
|
+
function (err, data) {
|
|
1618
|
+
if (err) return console.log(err);
|
|
1619
|
+
cos.putObjectCopy(
|
|
1620
|
+
{
|
|
1621
|
+
Bucket: config.Bucket,
|
|
1622
|
+
Region: config.Region,
|
|
1623
|
+
Key: target,
|
|
1624
|
+
CopySource: copySource,
|
|
1625
|
+
},
|
|
1626
|
+
function (err, data) {
|
|
1627
|
+
if (err) return console.log(err);
|
|
1628
|
+
cos.deleteObject(
|
|
1629
|
+
{
|
|
1630
|
+
Bucket: config.Bucket,
|
|
1631
|
+
Region: config.Region,
|
|
1632
|
+
Key: source,
|
|
1633
|
+
},
|
|
1634
|
+
function (err, data) {
|
|
1635
|
+
console.log(err || data);
|
|
1636
|
+
}
|
|
1637
|
+
);
|
|
1638
|
+
}
|
|
1639
|
+
);
|
|
1640
|
+
}
|
|
1641
|
+
);
|
|
1642
|
+
}
|
|
1643
|
+
|
|
1644
|
+
/* 上传本地文件夹 */
|
|
1645
|
+
function uploadFolder() {
|
|
1646
|
+
var localFolder = '../test/';
|
|
1647
|
+
var remotePrefix = 'folder/';
|
|
1648
|
+
util.fastListFolder(localFolder, function (err, list) {
|
|
1649
|
+
if (err) return console.error(err);
|
|
1650
|
+
var files = list.map(function (file) {
|
|
1651
|
+
var filename = pathLib.relative(localFolder, file.path).replace(/\\/g, '/');
|
|
1652
|
+
if (filename && file.isDir && !filename.endsWith('/')) filename += '/';
|
|
1653
|
+
var Key = remotePrefix + filename;
|
|
1654
|
+
return {
|
|
1655
|
+
Bucket: config.Bucket,
|
|
1656
|
+
Region: config.Region,
|
|
1657
|
+
Key: Key,
|
|
1658
|
+
FilePath: file.path,
|
|
1659
|
+
};
|
|
1660
|
+
});
|
|
1661
|
+
cos.uploadFiles(
|
|
1662
|
+
{
|
|
1663
|
+
files: files,
|
|
1664
|
+
SliceSize: 1024 * 1024,
|
|
1665
|
+
onProgress: function (info) {
|
|
1666
|
+
var percent = Math.floor(info.percent * 10000) / 100;
|
|
1667
|
+
var speed = Math.floor((info.speed / 1024 / 1024) * 100) / 100;
|
|
1668
|
+
console.log('进度:' + percent + '%; 速度:' + speed + 'Mb/s;');
|
|
1669
|
+
},
|
|
1670
|
+
onFileFinish: function (err, data, options) {
|
|
1671
|
+
console.log(options.Key + ' 上传' + (err ? '失败' : '完成'));
|
|
1672
|
+
},
|
|
1673
|
+
},
|
|
1674
|
+
function (err, data) {
|
|
1675
|
+
console.log(err || data);
|
|
1676
|
+
}
|
|
1677
|
+
);
|
|
1678
|
+
});
|
|
1679
|
+
}
|
|
1680
|
+
|
|
1681
|
+
/* 创建文件夹 */
|
|
1682
|
+
function createFolder() {
|
|
1683
|
+
cos.putObject(
|
|
1684
|
+
{
|
|
1685
|
+
Bucket: config.Bucket,
|
|
1686
|
+
Region: config.Region,
|
|
1687
|
+
Key: 'folder/', // 对象存储没有实际的文件夹,可以创建一个路径以 / 结尾的空对象表示,能在部分场景中满足文件夹使用需要
|
|
1688
|
+
Body: '',
|
|
1689
|
+
},
|
|
1690
|
+
function (err, data) {
|
|
1691
|
+
console.log(err || data);
|
|
1692
|
+
}
|
|
1693
|
+
);
|
|
1694
|
+
}
|
|
1695
|
+
|
|
1696
|
+
/* 列出文件夹下的文件 */
|
|
1697
|
+
function listFolder() {
|
|
1698
|
+
var _listFolder = function (params, callback) {
|
|
1699
|
+
var Contents = [];
|
|
1700
|
+
var CommonPrefixes = [];
|
|
1701
|
+
var marker;
|
|
1702
|
+
var next = function () {
|
|
1703
|
+
params.Marker = marker;
|
|
1704
|
+
cos.getBucket(params, function (err, data) {
|
|
1705
|
+
if (err) return callback(err);
|
|
1706
|
+
data &&
|
|
1707
|
+
data.CommonPrefixes &&
|
|
1708
|
+
data.CommonPrefixes.forEach(function (item) {
|
|
1709
|
+
CommonPrefixes.push(item);
|
|
1710
|
+
});
|
|
1711
|
+
data &&
|
|
1712
|
+
data.Contents &&
|
|
1713
|
+
data.Contents.forEach(function (item) {
|
|
1714
|
+
Contents.push(item);
|
|
1715
|
+
});
|
|
1716
|
+
if (data.IsTruncated === 'true') {
|
|
1717
|
+
marker = data.NextMarker;
|
|
1718
|
+
next();
|
|
1719
|
+
} else {
|
|
1720
|
+
callback(null, {
|
|
1721
|
+
CommonPrefixes: CommonPrefixes,
|
|
1722
|
+
Contents: Contents,
|
|
1723
|
+
});
|
|
1724
|
+
}
|
|
1725
|
+
});
|
|
1726
|
+
};
|
|
1727
|
+
next();
|
|
1728
|
+
};
|
|
1729
|
+
_listFolder(
|
|
1730
|
+
{
|
|
1731
|
+
Bucket: config.Bucket,
|
|
1732
|
+
Region: config.Region,
|
|
1733
|
+
Delimiter: '/', // 如果按目录列出文件传入该分隔符,如果要深度列出文件不传改参数
|
|
1734
|
+
Prefix: 'folder/', // 要列出的目录前缀
|
|
1735
|
+
},
|
|
1736
|
+
function (err, data) {
|
|
1737
|
+
console.log(err || data);
|
|
1738
|
+
}
|
|
1739
|
+
);
|
|
1740
|
+
}
|
|
1741
|
+
|
|
1742
|
+
/* 删除指定文件夹下的所有对象(删除存储桶里指定前缀所有对象) */
|
|
1743
|
+
function deleteFolder() {
|
|
1744
|
+
var _deleteFolder = function (params, callback) {
|
|
1745
|
+
var deletedList = [];
|
|
1746
|
+
var errorList = [];
|
|
1747
|
+
var marker;
|
|
1748
|
+
var next = function () {
|
|
1749
|
+
params.Marker = marker;
|
|
1750
|
+
cos.getBucket(params, function (err, data) {
|
|
1751
|
+
if (err) return callback(err);
|
|
1752
|
+
var Objects = [];
|
|
1753
|
+
if (data && data.Contents && data.Contents.length) {
|
|
1754
|
+
data.Contents.forEach(function (item) {
|
|
1755
|
+
Objects.push({ Key: item.Key });
|
|
1756
|
+
});
|
|
1757
|
+
}
|
|
1758
|
+
var afterDeleted = function () {
|
|
1759
|
+
if (data.IsTruncated === 'true') {
|
|
1760
|
+
marker = data.NextMarker;
|
|
1761
|
+
next();
|
|
1762
|
+
} else {
|
|
1763
|
+
callback(null, { Deleted: deletedList, Error: errorList });
|
|
1764
|
+
}
|
|
1765
|
+
};
|
|
1766
|
+
if (Objects.length) {
|
|
1767
|
+
cos.deleteMultipleObject(
|
|
1768
|
+
{
|
|
1769
|
+
Bucket: params.Bucket,
|
|
1770
|
+
Region: params.Region,
|
|
1771
|
+
Objects: Objects,
|
|
1772
|
+
},
|
|
1773
|
+
function (err, data) {
|
|
1774
|
+
data.Deleted &&
|
|
1775
|
+
data.Deleted.forEach(function (item) {
|
|
1776
|
+
deletedList.push(item);
|
|
1777
|
+
});
|
|
1778
|
+
data.Error &&
|
|
1779
|
+
data.Error.forEach(function (item) {
|
|
1780
|
+
errorList.push(item);
|
|
1781
|
+
});
|
|
1782
|
+
afterDeleted();
|
|
1783
|
+
}
|
|
1784
|
+
);
|
|
1785
|
+
} else {
|
|
1786
|
+
afterDeleted();
|
|
1787
|
+
}
|
|
1788
|
+
});
|
|
1789
|
+
};
|
|
1790
|
+
next();
|
|
1791
|
+
};
|
|
1792
|
+
_deleteFolder(
|
|
1793
|
+
{
|
|
1794
|
+
Bucket: config.Bucket,
|
|
1795
|
+
Region: config.Region,
|
|
1796
|
+
Prefix: 'folder/', // 要列出的目录前缀
|
|
1797
|
+
},
|
|
1798
|
+
function (err, data) {
|
|
1799
|
+
console.log(err || data);
|
|
1800
|
+
}
|
|
1801
|
+
);
|
|
1802
|
+
}
|
|
1803
|
+
|
|
1804
|
+
/* 分片下载文件 */
|
|
1805
|
+
function downloadFile() {
|
|
1806
|
+
// 单文件分片并发下载
|
|
1807
|
+
var Key = 'windows_7_ultimate_x64.iso';
|
|
1808
|
+
cos.downloadFile(
|
|
1809
|
+
{
|
|
1810
|
+
Bucket: config.Bucket,
|
|
1811
|
+
Region: config.Region,
|
|
1812
|
+
Key: Key,
|
|
1813
|
+
FilePath: './' + Key,
|
|
1814
|
+
ChunkSize: 1024 * 1024 * 8, // 文件大于 8MB 用分片下载
|
|
1815
|
+
ParallelLimit: 5, // 分片并发数
|
|
1816
|
+
RetryTimes: 3, // 分片失败重试次数
|
|
1817
|
+
TaskId: '123',
|
|
1818
|
+
onProgress: function (progressData) {
|
|
1819
|
+
console.log(JSON.stringify(progressData));
|
|
1820
|
+
},
|
|
1821
|
+
},
|
|
1822
|
+
function (err, data) {
|
|
1823
|
+
console.log(err || data);
|
|
1824
|
+
}
|
|
1825
|
+
);
|
|
1826
|
+
|
|
1827
|
+
// 取消下载任务
|
|
1828
|
+
// cos.emit('inner-kill-task', {TaskId: '123'});
|
|
1829
|
+
}
|
|
1830
|
+
|
|
1831
|
+
// 追加上传
|
|
1832
|
+
function appendObject() {
|
|
1833
|
+
cos.appendObject(
|
|
1834
|
+
{
|
|
1835
|
+
Bucket: config.Bucket, // Bucket 格式:test-1250000000
|
|
1836
|
+
Region: config.Region,
|
|
1837
|
+
Key: 'append1.txt' /* 必须 */,
|
|
1838
|
+
Body: '12345',
|
|
1839
|
+
Position: 0,
|
|
1840
|
+
},
|
|
1841
|
+
function (err, data) {
|
|
1842
|
+
console.log(err || data);
|
|
1843
|
+
}
|
|
1844
|
+
);
|
|
1845
|
+
}
|
|
1846
|
+
|
|
1847
|
+
// 继续追加上传
|
|
1848
|
+
function appendObject_continue() {
|
|
1849
|
+
cos.headObject(
|
|
1850
|
+
{
|
|
1851
|
+
Bucket: config.Bucket, // Bucket 格式:test-1250000000
|
|
1852
|
+
Region: config.Region,
|
|
1853
|
+
Key: 'append1.txt' /* 必须 */,
|
|
1854
|
+
},
|
|
1855
|
+
function (err, data) {
|
|
1856
|
+
if (err) return console.log(err);
|
|
1857
|
+
// 首先取到要追加的文件当前长度,即需要上送的Position
|
|
1858
|
+
var position = data.headers && data.headers['content-length'];
|
|
1859
|
+
cos.appendObject(
|
|
1860
|
+
{
|
|
1861
|
+
Bucket: config.Bucket, // Bucket 格式:test-1250000000
|
|
1862
|
+
Region: config.Region,
|
|
1863
|
+
Key: 'append1.txt' /* 必须 */,
|
|
1864
|
+
Body: '66666',
|
|
1865
|
+
Position: position,
|
|
1866
|
+
},
|
|
1867
|
+
function (err, data) {
|
|
1868
|
+
// 也可以取到下一次上传的position继续追加上传
|
|
1869
|
+
var nextPosition = data.headers && data.headers['x-cos-next-append-position'];
|
|
1870
|
+
console.log(err || data);
|
|
1871
|
+
}
|
|
1872
|
+
);
|
|
1873
|
+
}
|
|
1874
|
+
);
|
|
1875
|
+
}
|
|
1876
|
+
|
|
1877
|
+
function request() {
|
|
1878
|
+
// 对云上数据进行图片处理
|
|
1879
|
+
var filename = 'example_photo.png';
|
|
1880
|
+
cos.request(
|
|
1881
|
+
{
|
|
1882
|
+
Bucket: config.Bucket,
|
|
1883
|
+
Region: config.Region,
|
|
1884
|
+
Key: filename,
|
|
1885
|
+
Method: 'POST',
|
|
1886
|
+
Action: 'image_process',
|
|
1887
|
+
Headers: {
|
|
1888
|
+
// 万象持久化接口,上传时持久化
|
|
1889
|
+
'Pic-Operations':
|
|
1890
|
+
'{"is_pic_info": 1, "rules": [{"fileid": "example_photo_ci_result.png", "rule": "imageMogr2/thumbnail/200x/"}]}',
|
|
1891
|
+
},
|
|
1892
|
+
},
|
|
1893
|
+
function (err, data) {
|
|
1894
|
+
console.log(err || data);
|
|
1895
|
+
}
|
|
1896
|
+
);
|
|
1897
|
+
}
|
|
1898
|
+
|
|
1899
|
+
/**
|
|
1900
|
+
* function CIExample1
|
|
1901
|
+
* @description 上传时使用图片处理
|
|
1902
|
+
*/
|
|
1903
|
+
function CIExample1() {
|
|
1904
|
+
var filename = 'example_photo.png';
|
|
1905
|
+
var filepath = path.resolve(__dirname, filename);
|
|
1906
|
+
cos.putObject(
|
|
1907
|
+
{
|
|
1908
|
+
Bucket: config.Bucket, // Bucket 格式:test-1250000000
|
|
1909
|
+
Region: config.Region,
|
|
1910
|
+
Key: filename,
|
|
1911
|
+
Body: fs.readFileSync(filepath),
|
|
1912
|
+
Headers: {
|
|
1913
|
+
// 通过 imageMogr2 接口使用图片缩放功能:指定图片宽度为 100,宽度等比压缩
|
|
1914
|
+
'Pic-Operations':
|
|
1915
|
+
'{"is_pic_info": 1, "rules": [{"fileid": "example_photo_ci_result.png", "rule": "imageMogr2/thumbnail/200x/"}]}',
|
|
1916
|
+
},
|
|
1917
|
+
onTaskReady: function (tid) {
|
|
1918
|
+
TaskId = tid;
|
|
1919
|
+
},
|
|
1920
|
+
onProgress: function (progressData) {
|
|
1921
|
+
console.log(JSON.stringify(progressData));
|
|
1922
|
+
},
|
|
1923
|
+
},
|
|
1924
|
+
function (err, data) {
|
|
1925
|
+
console.log(err || data);
|
|
1926
|
+
}
|
|
1927
|
+
);
|
|
1928
|
+
}
|
|
1929
|
+
|
|
1930
|
+
/**
|
|
1931
|
+
* function CIExample2
|
|
1932
|
+
* @description 对云上数据进行图片处理
|
|
1933
|
+
*/
|
|
1934
|
+
function CIExample2() {
|
|
1935
|
+
var filename = 'example_photo.png';
|
|
1936
|
+
cos.request(
|
|
1937
|
+
{
|
|
1938
|
+
Bucket: config.Bucket,
|
|
1939
|
+
Region: config.Region,
|
|
1940
|
+
Key: filename,
|
|
1941
|
+
Method: 'POST',
|
|
1942
|
+
Action: 'image_process',
|
|
1943
|
+
Headers: {
|
|
1944
|
+
// 通过 imageMogr2 接口使用图片缩放功能:指定图片宽度为 200,宽度等比压缩
|
|
1945
|
+
'Pic-Operations':
|
|
1946
|
+
'{"is_pic_info": 1, "rules": [{"fileid": "example_photo_ci_result.png", "rule": "imageMogr2/thumbnail/200x/"}]}',
|
|
1947
|
+
},
|
|
1948
|
+
},
|
|
1949
|
+
function (err, data) {
|
|
1950
|
+
console.log(err || data);
|
|
1951
|
+
}
|
|
1952
|
+
);
|
|
1953
|
+
}
|
|
1954
|
+
|
|
1955
|
+
/**
|
|
1956
|
+
* function CIExample3
|
|
1957
|
+
* @description 下载时使用图片处理
|
|
1958
|
+
*/
|
|
1959
|
+
function CIExample3() {
|
|
1960
|
+
var filepath = path.resolve(__dirname, 'example_photo_ci_result.png');
|
|
1961
|
+
cos.getObject(
|
|
1962
|
+
{
|
|
1963
|
+
Bucket: config.Bucket,
|
|
1964
|
+
Region: config.Region,
|
|
1965
|
+
Key: 'example_photo.png',
|
|
1966
|
+
QueryString: 'imageMogr2/thumbnail/200x/',
|
|
1967
|
+
},
|
|
1968
|
+
function (err, data) {
|
|
1969
|
+
if (data) {
|
|
1970
|
+
fs.writeFileSync(filepath, data.Body);
|
|
1971
|
+
} else {
|
|
1972
|
+
console.log(err);
|
|
1973
|
+
}
|
|
1974
|
+
}
|
|
1975
|
+
);
|
|
1976
|
+
}
|
|
1977
|
+
|
|
1978
|
+
/**
|
|
1979
|
+
* function CIExample4
|
|
1980
|
+
* @description 生成带图片处理参数的签名 URL
|
|
1981
|
+
*/
|
|
1982
|
+
function CIExample4() {
|
|
1983
|
+
// 生成带图片处理参数的文件签名URL,过期时间设置为 30 分钟。
|
|
1984
|
+
cos.getObjectUrl(
|
|
1985
|
+
{
|
|
1986
|
+
Bucket: config.Bucket,
|
|
1987
|
+
Region: config.Region,
|
|
1988
|
+
Key: 'photo.png',
|
|
1989
|
+
QueryString: 'imageMogr2/thumbnail/200x/',
|
|
1990
|
+
Expires: 1800,
|
|
1991
|
+
Sign: true,
|
|
1992
|
+
},
|
|
1993
|
+
function (err, data) {
|
|
1994
|
+
console.log(err || data);
|
|
1995
|
+
}
|
|
1996
|
+
);
|
|
1997
|
+
|
|
1998
|
+
// 生成带图片处理参数的文件URL,不带签名。
|
|
1999
|
+
cos.getObjectUrl(
|
|
2000
|
+
{
|
|
2001
|
+
Bucket: config.Bucket,
|
|
2002
|
+
Region: config.Region,
|
|
2003
|
+
Key: 'photo.png',
|
|
2004
|
+
QueryString: 'imageMogr2/thumbnail/200x/',
|
|
2005
|
+
Sign: false,
|
|
2006
|
+
},
|
|
2007
|
+
function (err, data) {
|
|
2008
|
+
console.log(err || data);
|
|
2009
|
+
}
|
|
2010
|
+
);
|
|
2011
|
+
}
|
|
2012
|
+
|
|
2013
|
+
/**
|
|
2014
|
+
* 查询已经开通数据万象功能的存储桶
|
|
2015
|
+
*/
|
|
2016
|
+
function DescribeCIBuckets() {
|
|
2017
|
+
var host = 'ci.' + config.Region + '.myqcloud.com';
|
|
2018
|
+
var url = 'https://' + host + '/mediabucket';
|
|
2019
|
+
cos.request(
|
|
2020
|
+
{
|
|
2021
|
+
Bucket: config.Bucket,
|
|
2022
|
+
Region: config.Region,
|
|
2023
|
+
Method: 'GET',
|
|
2024
|
+
Key: 'mediabucket' /** 固定值,必须 */,
|
|
2025
|
+
Url: url,
|
|
2026
|
+
Query: {
|
|
2027
|
+
pageNumber: '1' /** 第几页,非必须 */,
|
|
2028
|
+
pageSize: '10' /** 每页个数,非必须 */,
|
|
2029
|
+
// regions: 'ap-chengdu', /** 地域信息,例如'ap-beijing',支持多个值用逗号分隔如'ap-shanghai,ap-beijing',非必须 */
|
|
2030
|
+
// bucketNames: 'test-1250000000', /** 存储桶名称,精确搜索,例如'test-1250000000',支持多个值用逗号分隔如'test1-1250000000,test2-1250000000',非必须 */
|
|
2031
|
+
// bucketName: 'test', /** 存储桶名称前缀,前缀搜索,例如'test',支持多个值用逗号分隔如'test1,test2',非必须 */
|
|
2032
|
+
},
|
|
2033
|
+
},
|
|
2034
|
+
function (err, data) {
|
|
2035
|
+
// var CIStatus = data.CIStatus;
|
|
2036
|
+
console.log(err || data);
|
|
2037
|
+
}
|
|
2038
|
+
);
|
|
2039
|
+
}
|
|
2040
|
+
|
|
2041
|
+
/**
|
|
2042
|
+
* 获取媒体文件信息
|
|
2043
|
+
*/
|
|
2044
|
+
function GetMediaInfo() {
|
|
2045
|
+
cos.request(
|
|
2046
|
+
{
|
|
2047
|
+
Bucket: config.Bucket,
|
|
2048
|
+
Region: config.Region,
|
|
2049
|
+
Method: 'GET',
|
|
2050
|
+
Key: 'test.mp4',
|
|
2051
|
+
Query: {
|
|
2052
|
+
'ci-process': 'videoinfo' /** 固定值,必须 */,
|
|
2053
|
+
},
|
|
2054
|
+
},
|
|
2055
|
+
function (err, data) {
|
|
2056
|
+
console.log(err || data);
|
|
2057
|
+
}
|
|
2058
|
+
);
|
|
2059
|
+
}
|
|
2060
|
+
|
|
2061
|
+
/**
|
|
2062
|
+
* 获取媒体文件某个时间的截图
|
|
2063
|
+
*/
|
|
2064
|
+
function GetSnapshot() {
|
|
2065
|
+
cos.request(
|
|
2066
|
+
{
|
|
2067
|
+
Bucket: config.Bucket,
|
|
2068
|
+
Region: config.Region,
|
|
2069
|
+
Method: 'GET',
|
|
2070
|
+
Key: 'test.mp4',
|
|
2071
|
+
Query: {
|
|
2072
|
+
'ci-process': 'snapshot' /** 固定值,必须 */,
|
|
2073
|
+
time: 1 /** 截图的时间点,单位为秒,必须 */,
|
|
2074
|
+
// width: 0, /** 截图的宽,非必须 */
|
|
2075
|
+
// height: 0, /** 截图的高,非必须 */
|
|
2076
|
+
// format: 'jpg', /** 截图的格式,支持 jpg 和 png,默认 jpg,非必须 */
|
|
2077
|
+
// rotate: 'auto', /** 图片旋转方式,默认为'auto',非必须 */
|
|
2078
|
+
// mode: 'exactframe', /** 截帧方式,默认为'exactframe',非必须 */
|
|
2079
|
+
},
|
|
2080
|
+
RawBody: true,
|
|
2081
|
+
},
|
|
2082
|
+
function (err, data) {
|
|
2083
|
+
// var Body = data.Body;
|
|
2084
|
+
console.log(err || data);
|
|
2085
|
+
}
|
|
2086
|
+
);
|
|
2087
|
+
}
|
|
2088
|
+
|
|
2089
|
+
/**
|
|
2090
|
+
* 对多种文件类型生成图片格式或html格式预览
|
|
2091
|
+
*/
|
|
2092
|
+
function GetDocProcess() {
|
|
2093
|
+
cos.request(
|
|
2094
|
+
{
|
|
2095
|
+
Bucket: config.Bucket, // Bucket 格式:test-1250000000
|
|
2096
|
+
Region: config.Region,
|
|
2097
|
+
Method: 'GET',
|
|
2098
|
+
Key: 'test.pptx',
|
|
2099
|
+
Query: {
|
|
2100
|
+
'ci-process': 'doc-preview',
|
|
2101
|
+
page: '1',
|
|
2102
|
+
dstType: 'jpg',
|
|
2103
|
+
ImageParams:
|
|
2104
|
+
'imageMogr2/thumbnail/!50p|watermark/2/text/5pWw5o2u5LiH6LGh/fill/I0ZGRkZGRg==/fontsize/30/dx/20/dy/20',
|
|
2105
|
+
},
|
|
2106
|
+
},
|
|
2107
|
+
function (err, data) {
|
|
2108
|
+
console.log(err || data);
|
|
2109
|
+
}
|
|
2110
|
+
);
|
|
2111
|
+
}
|
|
2112
|
+
|
|
2113
|
+
/**
|
|
2114
|
+
* 查询文档转码队列
|
|
2115
|
+
*/
|
|
2116
|
+
function DescribeDocProcessQueues() {
|
|
2117
|
+
let host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com';
|
|
2118
|
+
let url = 'https://' + host + '/docqueue';
|
|
2119
|
+
cos.request(
|
|
2120
|
+
{
|
|
2121
|
+
Bucket: config.Bucket, // Bucket 格式:test-1250000000
|
|
2122
|
+
Region: config.Region,
|
|
2123
|
+
Method: 'GET',
|
|
2124
|
+
Key: 'docqueue',
|
|
2125
|
+
Url: url,
|
|
2126
|
+
Query: {
|
|
2127
|
+
state: 'Active',
|
|
2128
|
+
},
|
|
2129
|
+
},
|
|
2130
|
+
function (err, data) {
|
|
2131
|
+
console.log(err || data);
|
|
2132
|
+
}
|
|
2133
|
+
);
|
|
2134
|
+
}
|
|
2135
|
+
|
|
2136
|
+
/**
|
|
2137
|
+
* 更新文档转码队列
|
|
2138
|
+
*/
|
|
2139
|
+
function UpdateDocProcessQueue() {
|
|
2140
|
+
// 任务所在的队列 ID,请使用查询队列(https://cloud.tencent.com/document/product/460/46946)获取或前往万象控制台(https://cloud.tencent.com/document/product/460/46487)在存储桶中查询
|
|
2141
|
+
let queueId = 'p31299c0b3f4742dda2fc1be3ea40xxxx'; // 需要更新的队列ID
|
|
2142
|
+
let host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com';
|
|
2143
|
+
let url = 'https://' + host + '/docqueue/' + queueId;
|
|
2144
|
+
let body = {
|
|
2145
|
+
// 填上队列修改参数
|
|
2146
|
+
Request: {
|
|
2147
|
+
Name: '1',
|
|
2148
|
+
QueueID: queueId,
|
|
2149
|
+
State: 'Active',
|
|
2150
|
+
NotifyConfig: {
|
|
2151
|
+
Url: 'http://your.callkback.address/index.php',
|
|
2152
|
+
Type: 'Url',
|
|
2153
|
+
State: 'On',
|
|
2154
|
+
Event: 'TaskFinish',
|
|
2155
|
+
},
|
|
2156
|
+
},
|
|
2157
|
+
};
|
|
2158
|
+
cos.request(
|
|
2159
|
+
{
|
|
2160
|
+
Bucket: config.Bucket, // Bucket 格式:test-1250000000
|
|
2161
|
+
Region: config.Region,
|
|
2162
|
+
Method: 'PUT',
|
|
2163
|
+
Key: 'docqueue/' + queueId,
|
|
2164
|
+
Url: url,
|
|
2165
|
+
Headers: {
|
|
2166
|
+
'content-type': 'application/xml',
|
|
2167
|
+
},
|
|
2168
|
+
Body: json2xml(body),
|
|
2169
|
+
},
|
|
2170
|
+
function (err, data) {
|
|
2171
|
+
console.log(err || data);
|
|
2172
|
+
}
|
|
2173
|
+
);
|
|
2174
|
+
}
|
|
2175
|
+
|
|
2176
|
+
/**
|
|
2177
|
+
* 创建文档转码任务
|
|
2178
|
+
*/
|
|
2179
|
+
function CreateDocProcessJobs() {
|
|
2180
|
+
let queueId = 'p31299c0b3f4742dda2fc1be3ea40xxxx'; // 队列ID
|
|
2181
|
+
let host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com';
|
|
2182
|
+
let url = 'https://' + host + '/doc_jobs';
|
|
2183
|
+
let body = {
|
|
2184
|
+
// 填上任务参数
|
|
2185
|
+
Request: {
|
|
2186
|
+
Tag: 'DocProcess',
|
|
2187
|
+
Input: {
|
|
2188
|
+
Object: 'test.pptx',
|
|
2189
|
+
},
|
|
2190
|
+
QueueId: queueId,
|
|
2191
|
+
Operation: {
|
|
2192
|
+
DocProcess: {
|
|
2193
|
+
StartPage: 3,
|
|
2194
|
+
EndPage: 4,
|
|
2195
|
+
TgtType: 'png',
|
|
2196
|
+
},
|
|
2197
|
+
Output: {
|
|
2198
|
+
Region: config.Region,
|
|
2199
|
+
Bucket: config.Bucket,
|
|
2200
|
+
Object: 'doc_${Page}.png',
|
|
2201
|
+
},
|
|
2202
|
+
},
|
|
2203
|
+
},
|
|
2204
|
+
};
|
|
2205
|
+
cos.request(
|
|
2206
|
+
{
|
|
2207
|
+
Bucket: config.Bucket, // Bucket 格式:test-1250000000
|
|
2208
|
+
Region: config.Region,
|
|
2209
|
+
Method: 'POST',
|
|
2210
|
+
Key: 'doc_jobs',
|
|
2211
|
+
Url: url,
|
|
2212
|
+
Headers: {
|
|
2213
|
+
'content-type': 'application/xml',
|
|
2214
|
+
},
|
|
2215
|
+
Body: json2xml(body),
|
|
2216
|
+
},
|
|
2217
|
+
function (err, data) {
|
|
2218
|
+
console.log(err || data);
|
|
2219
|
+
}
|
|
2220
|
+
);
|
|
2221
|
+
}
|
|
2222
|
+
|
|
2223
|
+
/**
|
|
2224
|
+
* 查询文档转码任务
|
|
2225
|
+
*/
|
|
2226
|
+
function DescribeDocProcessJob() {
|
|
2227
|
+
let jobId = 'd2c6c620a415811ecb31b51515222xxxx';
|
|
2228
|
+
let host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com';
|
|
2229
|
+
let url = 'https://' + host + '/doc_jobs/' + jobId;
|
|
2230
|
+
cos.request(
|
|
2231
|
+
{
|
|
2232
|
+
Bucket: config.Bucket, // Bucket 格式:test-1250000000
|
|
2233
|
+
Region: config.Region,
|
|
2234
|
+
Method: 'GET',
|
|
2235
|
+
Key: 'doc_jobs/' + jobId,
|
|
2236
|
+
Url: url,
|
|
2237
|
+
},
|
|
2238
|
+
function (err, data) {
|
|
2239
|
+
console.log(err || data);
|
|
2240
|
+
}
|
|
2241
|
+
);
|
|
2242
|
+
}
|
|
2243
|
+
|
|
2244
|
+
/**
|
|
2245
|
+
* 文档转码任务列表
|
|
2246
|
+
*/
|
|
2247
|
+
function DescribeDocProcessJobs() {
|
|
2248
|
+
let queueId = 'p31299c0b3f4742dda2fc1be3ea40xxxx';
|
|
2249
|
+
let host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com';
|
|
2250
|
+
let url = 'https://' + host + '/doc_jobs';
|
|
2251
|
+
cos.request(
|
|
2252
|
+
{
|
|
2253
|
+
Bucket: config.Bucket, // Bucket 格式:test-1250000000
|
|
2254
|
+
Region: config.Region,
|
|
2255
|
+
Method: 'GET',
|
|
2256
|
+
Key: 'doc_jobs',
|
|
2257
|
+
Url: url,
|
|
2258
|
+
Query: {
|
|
2259
|
+
tag: 'DocProcess',
|
|
2260
|
+
queueId: queueId,
|
|
2261
|
+
states: 'Failed',
|
|
2262
|
+
},
|
|
2263
|
+
},
|
|
2264
|
+
function (err, data) {
|
|
2265
|
+
console.log(err || data);
|
|
2266
|
+
}
|
|
2267
|
+
);
|
|
2268
|
+
}
|
|
2269
|
+
|
|
2270
|
+
/**
|
|
2271
|
+
* 查询已经开通媒体处理功能的存储桶
|
|
2272
|
+
*/
|
|
2273
|
+
function DescribeMediaBuckets() {
|
|
2274
|
+
let host = 'ci.' + config.Region + '.myqcloud.com';
|
|
2275
|
+
let url = 'https://' + host + '/mediabucket';
|
|
2276
|
+
cos.request(
|
|
2277
|
+
{
|
|
2278
|
+
Bucket: config.Bucket, // Bucket 格式:test-1250000000
|
|
2279
|
+
Region: config.Region,
|
|
2280
|
+
Method: 'GET',
|
|
2281
|
+
Key: 'mediabucket',
|
|
2282
|
+
Url: url,
|
|
2283
|
+
Query: {
|
|
2284
|
+
pageNumber: '1',
|
|
2285
|
+
pageSize: '10',
|
|
2286
|
+
},
|
|
2287
|
+
},
|
|
2288
|
+
function (err, data) {
|
|
2289
|
+
console.log(err || data);
|
|
2290
|
+
}
|
|
2291
|
+
);
|
|
2292
|
+
}
|
|
2293
|
+
|
|
2294
|
+
/**
|
|
2295
|
+
* 查询存储桶的媒体处理队列
|
|
2296
|
+
*/
|
|
2297
|
+
function DescribeMediaQueues() {
|
|
2298
|
+
let host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com';
|
|
2299
|
+
let url = 'https://' + host + '/queue';
|
|
2300
|
+
cos.request(
|
|
2301
|
+
{
|
|
2302
|
+
Bucket: config.Bucket, // Bucket 格式:test-1250000000
|
|
2303
|
+
Region: config.Region,
|
|
2304
|
+
Method: 'GET',
|
|
2305
|
+
Key: 'queue',
|
|
2306
|
+
Url: url,
|
|
2307
|
+
},
|
|
2308
|
+
function (err, data) {
|
|
2309
|
+
console.log(err || data);
|
|
2310
|
+
}
|
|
2311
|
+
);
|
|
2312
|
+
}
|
|
2313
|
+
|
|
2314
|
+
/**
|
|
2315
|
+
* 更新媒体处理队列
|
|
2316
|
+
*/
|
|
2317
|
+
function UpdateMediaQueue() {
|
|
2318
|
+
let queueId = 'p5ad1499214024af2bfaa4401d529xxxx'; // 需要更新的队列ID
|
|
2319
|
+
let host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com';
|
|
2320
|
+
let url = 'https://' + host + '/queue/' + queueId;
|
|
2321
|
+
let body = {
|
|
2322
|
+
// 填上队列修改参数
|
|
2323
|
+
Request: {
|
|
2324
|
+
Name: '1',
|
|
2325
|
+
QueueID: queueId,
|
|
2326
|
+
State: 'Active',
|
|
2327
|
+
NotifyConfig: {
|
|
2328
|
+
Url: 'http://your.callkback.address/index.php',
|
|
2329
|
+
Type: 'Url',
|
|
2330
|
+
Event: 'TaskFinish',
|
|
2331
|
+
State: 'On',
|
|
2332
|
+
},
|
|
2333
|
+
},
|
|
2334
|
+
};
|
|
2335
|
+
cos.request(
|
|
2336
|
+
{
|
|
2337
|
+
Bucket: config.Bucket, // Bucket 格式:test-1250000000
|
|
2338
|
+
Region: config.Region,
|
|
2339
|
+
Method: 'PUT',
|
|
2340
|
+
Key: 'queue/' + queueId,
|
|
2341
|
+
Url: url,
|
|
2342
|
+
Headers: {
|
|
2343
|
+
'content-type': 'application/xml',
|
|
2344
|
+
},
|
|
2345
|
+
Body: json2xml(body),
|
|
2346
|
+
},
|
|
2347
|
+
function (err, data) {
|
|
2348
|
+
console.log(err || data);
|
|
2349
|
+
}
|
|
2350
|
+
);
|
|
2351
|
+
}
|
|
2352
|
+
|
|
2353
|
+
/**
|
|
2354
|
+
* 创建媒体处理的各种模版(以截帧模版为例)
|
|
2355
|
+
*/
|
|
2356
|
+
function CreateMediaTemplate() {
|
|
2357
|
+
let host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com';
|
|
2358
|
+
let url = 'https://' + host + '/template';
|
|
2359
|
+
let body = {
|
|
2360
|
+
// 填上模板参数
|
|
2361
|
+
Request: {
|
|
2362
|
+
Tag: 'Snapshot',
|
|
2363
|
+
Name: 'test-template',
|
|
2364
|
+
Snapshot: {
|
|
2365
|
+
Mode: 'Interval',
|
|
2366
|
+
Start: '1',
|
|
2367
|
+
TimeInterval: '5',
|
|
2368
|
+
Count: '3',
|
|
2369
|
+
Width: '1280',
|
|
2370
|
+
},
|
|
2371
|
+
},
|
|
2372
|
+
};
|
|
2373
|
+
cos.request(
|
|
2374
|
+
{
|
|
2375
|
+
Bucket: config.Bucket, // Bucket 格式:test-1250000000
|
|
2376
|
+
Region: config.Region,
|
|
2377
|
+
Method: 'POST',
|
|
2378
|
+
Key: 'template',
|
|
2379
|
+
Url: url,
|
|
2380
|
+
Headers: {
|
|
2381
|
+
'content-type': 'application/xml',
|
|
2382
|
+
},
|
|
2383
|
+
Body: json2xml(body),
|
|
2384
|
+
},
|
|
2385
|
+
function (err, data) {
|
|
2386
|
+
console.log(err || data);
|
|
2387
|
+
}
|
|
2388
|
+
);
|
|
2389
|
+
}
|
|
2390
|
+
|
|
2391
|
+
/**
|
|
2392
|
+
* 删除模版
|
|
2393
|
+
*/
|
|
2394
|
+
function DeleteMediaTemplate() {
|
|
2395
|
+
let templateId = 't1b11b39d3a91949d6804c08399186xxxx'; // 待删除的模版ID
|
|
2396
|
+
let host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com';
|
|
2397
|
+
let url = 'https://' + host + '/template/' + templateId;
|
|
2398
|
+
cos.request(
|
|
2399
|
+
{
|
|
2400
|
+
Bucket: config.Bucket, // Bucket 格式:test-1250000000
|
|
2401
|
+
Region: config.Region,
|
|
2402
|
+
Method: 'DELETE',
|
|
2403
|
+
Key: 'template/' + templateId,
|
|
2404
|
+
Url: url,
|
|
2405
|
+
Headers: {
|
|
2406
|
+
'content-type': 'application/xml',
|
|
2407
|
+
},
|
|
2408
|
+
},
|
|
2409
|
+
function (err, data) {
|
|
2410
|
+
console.log(err || data);
|
|
2411
|
+
}
|
|
2412
|
+
);
|
|
2413
|
+
}
|
|
2414
|
+
|
|
2415
|
+
/**
|
|
2416
|
+
* 查看模版详情
|
|
2417
|
+
*/
|
|
2418
|
+
function DescribeMediaTemplates() {
|
|
2419
|
+
let host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com';
|
|
2420
|
+
let url = 'https://' + host + '/template';
|
|
2421
|
+
cos.request(
|
|
2422
|
+
{
|
|
2423
|
+
Bucket: config.Bucket, // Bucket 格式:test-1250000000
|
|
2424
|
+
Region: config.Region,
|
|
2425
|
+
Method: 'GET',
|
|
2426
|
+
Key: 'template',
|
|
2427
|
+
Url: url,
|
|
2428
|
+
Headers: {
|
|
2429
|
+
'content-type': 'application/xml',
|
|
2430
|
+
},
|
|
2431
|
+
Query: {
|
|
2432
|
+
tag: 'Snapshot',
|
|
2433
|
+
name: 'test',
|
|
2434
|
+
},
|
|
2435
|
+
},
|
|
2436
|
+
function (err, data) {
|
|
2437
|
+
console.log(err || data);
|
|
2438
|
+
}
|
|
2439
|
+
);
|
|
2440
|
+
}
|
|
2441
|
+
|
|
2442
|
+
/**
|
|
2443
|
+
* 更新模版信息
|
|
2444
|
+
*/
|
|
2445
|
+
function UpdateMediaTemplate() {
|
|
2446
|
+
let templateId = 't12cf1cde8d8a845eebc0a5c6047bfxxxx'; // 需要更新的模版ID
|
|
2447
|
+
let host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com';
|
|
2448
|
+
let url = 'https://' + host + '/template/' + templateId;
|
|
2449
|
+
let body = {
|
|
2450
|
+
// 填上模版修改参数
|
|
2451
|
+
Request: {
|
|
2452
|
+
Tag: 'Snapshot',
|
|
2453
|
+
Name: 'test-new',
|
|
2454
|
+
Snapshot: {
|
|
2455
|
+
Mode: 'Average',
|
|
2456
|
+
Start: '0',
|
|
2457
|
+
Count: '3',
|
|
2458
|
+
Height: '1280',
|
|
2459
|
+
},
|
|
2460
|
+
},
|
|
2461
|
+
};
|
|
2462
|
+
cos.request(
|
|
2463
|
+
{
|
|
2464
|
+
Bucket: config.Bucket, // Bucket 格式:test-1250000000
|
|
2465
|
+
Region: config.Region,
|
|
2466
|
+
Method: 'PUT',
|
|
2467
|
+
Key: 'template/' + templateId,
|
|
2468
|
+
Url: url,
|
|
2469
|
+
Headers: {
|
|
2470
|
+
'content-type': 'application/xml',
|
|
2471
|
+
},
|
|
2472
|
+
Body: json2xml(body),
|
|
2473
|
+
},
|
|
2474
|
+
function (err, data) {
|
|
2475
|
+
console.log(err || data);
|
|
2476
|
+
}
|
|
2477
|
+
);
|
|
2478
|
+
}
|
|
2479
|
+
|
|
2480
|
+
/**
|
|
2481
|
+
* 提交媒体处理任务
|
|
2482
|
+
*/
|
|
2483
|
+
function CreateMediaJobs() {
|
|
2484
|
+
let templateId = 't12cf1cde8d8a845eebc0a5c6047bfxxxx'; // 模版ID
|
|
2485
|
+
let queueId = 'p5ad1499214024af2bfaa4401d529xxxx'; // 队列ID
|
|
2486
|
+
let host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com';
|
|
2487
|
+
let url = 'https://' + host + '/jobs';
|
|
2488
|
+
let body = {
|
|
2489
|
+
// 填上任务参数
|
|
2490
|
+
Request: {
|
|
2491
|
+
Tag: 'Snapshot',
|
|
2492
|
+
Input: {
|
|
2493
|
+
Object: 'test-input.mp4',
|
|
2494
|
+
},
|
|
2495
|
+
QueueId: queueId,
|
|
2496
|
+
Operation: {
|
|
2497
|
+
TemplateId: templateId,
|
|
2498
|
+
Output: {
|
|
2499
|
+
Region: config.Region,
|
|
2500
|
+
Bucket: config.Bucket,
|
|
2501
|
+
Object: 'test-output${Number}',
|
|
2502
|
+
},
|
|
2503
|
+
},
|
|
2504
|
+
CallBack: 'http://your.task.callkback.address/index.php',
|
|
2505
|
+
},
|
|
2506
|
+
};
|
|
2507
|
+
cos.request(
|
|
2508
|
+
{
|
|
2509
|
+
Bucket: config.Bucket, // Bucket 格式:test-1250000000
|
|
2510
|
+
Region: config.Region,
|
|
2511
|
+
Method: 'POST',
|
|
2512
|
+
Key: 'jobs',
|
|
2513
|
+
Url: url,
|
|
2514
|
+
Headers: {
|
|
2515
|
+
'content-type': 'application/xml',
|
|
2516
|
+
},
|
|
2517
|
+
Body: json2xml(body),
|
|
2518
|
+
},
|
|
2519
|
+
function (err, data) {
|
|
2520
|
+
console.log(err || data);
|
|
2521
|
+
}
|
|
2522
|
+
);
|
|
2523
|
+
}
|
|
2524
|
+
|
|
2525
|
+
/**
|
|
2526
|
+
* 取消媒体处理任务
|
|
2527
|
+
*/
|
|
2528
|
+
function CancelMediaJob() {
|
|
2529
|
+
let jobId = 'j14596fda409c11eca160977fff35xxxx'; // 待取消的任务ID
|
|
2530
|
+
let host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com';
|
|
2531
|
+
let url = 'https://' + host + '/jobs/' + jobId;
|
|
2532
|
+
cos.request(
|
|
2533
|
+
{
|
|
2534
|
+
Bucket: config.Bucket, // Bucket 格式:test-1250000000
|
|
2535
|
+
Region: config.Region,
|
|
2536
|
+
Method: 'PUT',
|
|
2537
|
+
Key: 'jobs/' + jobId,
|
|
2538
|
+
Url: url,
|
|
2539
|
+
},
|
|
2540
|
+
function (err, data) {
|
|
2541
|
+
console.log(err || data);
|
|
2542
|
+
}
|
|
2543
|
+
);
|
|
2544
|
+
}
|
|
2545
|
+
|
|
2546
|
+
/**
|
|
2547
|
+
* 查看媒体处理任务
|
|
2548
|
+
*/
|
|
2549
|
+
function DescribeMediaJob() {
|
|
2550
|
+
let jobId = 'j14596fda409c11eca160977fff35xxxx'; // 任务ID
|
|
2551
|
+
let host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com';
|
|
2552
|
+
let url = 'https://' + host + '/jobs/' + jobId;
|
|
2553
|
+
cos.request(
|
|
2554
|
+
{
|
|
2555
|
+
Bucket: config.Bucket, // Bucket 格式:test-1250000000
|
|
2556
|
+
Region: config.Region,
|
|
2557
|
+
Method: 'GET',
|
|
2558
|
+
Key: 'jobs/' + jobId,
|
|
2559
|
+
Url: url,
|
|
2560
|
+
},
|
|
2561
|
+
function (err, data) {
|
|
2562
|
+
console.log(err || data);
|
|
2563
|
+
}
|
|
2564
|
+
);
|
|
2565
|
+
}
|
|
2566
|
+
|
|
2567
|
+
/**
|
|
2568
|
+
* 媒体处理任务列表
|
|
2569
|
+
*/
|
|
2570
|
+
function DescribeMediaJobs() {
|
|
2571
|
+
let queueId = 'p5ad1499214024af2bfaa4401d529xxxx'; // 队列ID
|
|
2572
|
+
let host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com';
|
|
2573
|
+
let url = 'https://' + host + '/jobs';
|
|
2574
|
+
cos.request(
|
|
2575
|
+
{
|
|
2576
|
+
Bucket: config.Bucket, // Bucket 格式:test-1250000000
|
|
2577
|
+
Region: config.Region,
|
|
2578
|
+
Method: 'GET',
|
|
2579
|
+
Key: 'jobs',
|
|
2580
|
+
Url: url,
|
|
2581
|
+
Query: {
|
|
2582
|
+
queueId: queueId,
|
|
2583
|
+
tag: 'Snapshot',
|
|
2584
|
+
states: 'Failed',
|
|
2585
|
+
},
|
|
2586
|
+
},
|
|
2587
|
+
function (err, data) {
|
|
2588
|
+
console.log(err || data);
|
|
2589
|
+
}
|
|
2590
|
+
);
|
|
2591
|
+
}
|
|
2592
|
+
|
|
2593
|
+
/**
|
|
2594
|
+
* 创建工作流
|
|
2595
|
+
*/
|
|
2596
|
+
function CreateWorkflow() {
|
|
2597
|
+
let queueId = 'p5ad1499214024af2bfaa4401d529xxxx';
|
|
2598
|
+
let callbackUrl = 'http://your.callback.com/index.php';
|
|
2599
|
+
let snapshotTemplate = 't0a60a2bc71a4b40c7b3d7f7e8a277xxxx';
|
|
2600
|
+
let transcodeTemplate = 't04e1ab86554984f1aa17c062fbf6cxxxx';
|
|
2601
|
+
let animationTemplate = 't0341b0ab2b8a340ff826e9cb4f3a7xxxx';
|
|
2602
|
+
let concatTemplate = 't19e96c43b0c05444f9b2facc9dcf5xxxx';
|
|
2603
|
+
let voiceSeparateTemplate = 't1c101e2bc074c4506837714edc99axxxx';
|
|
2604
|
+
let videoMontageTemplate = 't1ec0b3871d5e340da84536688b810xxxx';
|
|
2605
|
+
let watermarkTemplate = 't1ea62f7810d0142c195313330bdd4xxxx';
|
|
2606
|
+
let videoProcessTemplate = 't1d945b6de362f4d4db9bd8659bc5exxxx';
|
|
2607
|
+
let superResolutionTemplate = 't1d9d5ae4450824427bccc495ed0b0xxxx';
|
|
2608
|
+
let host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com';
|
|
2609
|
+
let url = 'https://' + host + '/workflow';
|
|
2610
|
+
let body = {
|
|
2611
|
+
Request: {
|
|
2612
|
+
MediaWorkflow: {
|
|
2613
|
+
Name: 'demo',
|
|
2614
|
+
State: 'Active', // 创建并开启工作流
|
|
2615
|
+
Topology: {
|
|
2616
|
+
Dependencies: {
|
|
2617
|
+
Start:
|
|
2618
|
+
'Snapshot_1581665960536,Transcode_1581665960537,Animation_1581665960538,Concat_1581665960539,VoiceSeparate_1581665960551,VideoMontage_1581665960551,SDRtoHDR_1581665960553,VideoProcess_1581665960554,SuperResolution_1581665960583,Segment_1581665960667',
|
|
2619
|
+
Snapshot_1581665960536: 'End',
|
|
2620
|
+
Transcode_1581665960537: 'End',
|
|
2621
|
+
Animation_1581665960538: 'End',
|
|
2622
|
+
Concat_1581665960539: 'End',
|
|
2623
|
+
VideoMontage_1581665960551: 'End',
|
|
2624
|
+
SDRtoHDR_1581665960553: 'End',
|
|
2625
|
+
VideoProcess_1581665960554: 'End',
|
|
2626
|
+
SuperResolution_1581665960583: 'End',
|
|
2627
|
+
Segment_1581665960667: 'End',
|
|
2628
|
+
VoiceSeparate_1581665960551: 'End',
|
|
2629
|
+
},
|
|
2630
|
+
Nodes: {
|
|
2631
|
+
Start: {
|
|
2632
|
+
Type: 'Start',
|
|
2633
|
+
Input: {
|
|
2634
|
+
QueueId: queueId,
|
|
2635
|
+
ObjectPrefix: 'test-',
|
|
2636
|
+
NotifyConfig: {
|
|
2637
|
+
Type: 'Url',
|
|
2638
|
+
Url: callbackUrl,
|
|
2639
|
+
Event: 'TaskFinish,WorkflowFinish',
|
|
2640
|
+
},
|
|
2641
|
+
ExtFilter: {
|
|
2642
|
+
State: 'On',
|
|
2643
|
+
Audio: 'true',
|
|
2644
|
+
Custom: 'true',
|
|
2645
|
+
CustomExts: 'mp4/mp3',
|
|
2646
|
+
AllFile: 'false',
|
|
2647
|
+
},
|
|
2648
|
+
},
|
|
2649
|
+
},
|
|
2650
|
+
Snapshot_1581665960536: {
|
|
2651
|
+
Type: 'Snapshot',
|
|
2652
|
+
Operation: {
|
|
2653
|
+
TemplateId: snapshotTemplate,
|
|
2654
|
+
Output: {
|
|
2655
|
+
Region: config.Region,
|
|
2656
|
+
Bucket: config.Bucket,
|
|
2657
|
+
Object: 'worlflow-test/${RunId}/snapshot-${number}.${Ext}',
|
|
2658
|
+
SpriteObject: 'worlflow-test/${RunId}/snapshot-sprite-${number}.jpg',
|
|
2659
|
+
},
|
|
2660
|
+
},
|
|
2661
|
+
},
|
|
2662
|
+
Transcode_1581665960537: {
|
|
2663
|
+
Type: 'Transcode',
|
|
2664
|
+
Operation: {
|
|
2665
|
+
TemplateId: transcodeTemplate,
|
|
2666
|
+
Output: {
|
|
2667
|
+
Region: config.Region,
|
|
2668
|
+
Bucket: config.Bucket,
|
|
2669
|
+
Object: 'worlflow-test/${RunId}/trans.mp4',
|
|
2670
|
+
},
|
|
2671
|
+
},
|
|
2672
|
+
},
|
|
2673
|
+
Animation_1581665960538: {
|
|
2674
|
+
Type: 'Animation',
|
|
2675
|
+
Operation: {
|
|
2676
|
+
TemplateId: animationTemplate,
|
|
2677
|
+
Output: {
|
|
2678
|
+
Region: config.Region,
|
|
2679
|
+
Bucket: config.Bucket,
|
|
2680
|
+
Object: 'worlflow-test/${RunId}/bcd.gif',
|
|
2681
|
+
},
|
|
2682
|
+
},
|
|
2683
|
+
},
|
|
2684
|
+
Concat_1581665960539: {
|
|
2685
|
+
Type: 'Concat',
|
|
2686
|
+
Operation: {
|
|
2687
|
+
TemplateId: concatTemplate,
|
|
2688
|
+
Output: {
|
|
2689
|
+
Region: config.Region,
|
|
2690
|
+
Bucket: config.Bucket,
|
|
2691
|
+
Object: 'worlflow-test/${RunId}/abc.${ext}',
|
|
2692
|
+
},
|
|
2693
|
+
},
|
|
2694
|
+
},
|
|
2695
|
+
VoiceSeparate_1581665960551: {
|
|
2696
|
+
Type: 'VoiceSeparate',
|
|
2697
|
+
Operation: {
|
|
2698
|
+
TemplateId: voiceSeparateTemplate,
|
|
2699
|
+
Output: {
|
|
2700
|
+
Region: config.Region,
|
|
2701
|
+
Bucket: config.Bucket,
|
|
2702
|
+
Object: 'worlflow-test/${RunId}/background.mp3',
|
|
2703
|
+
AuObject: 'worlflow-test/${RunId}/audio.mp3',
|
|
2704
|
+
},
|
|
2705
|
+
},
|
|
2706
|
+
},
|
|
2707
|
+
VideoMontage_1581665960551: {
|
|
2708
|
+
Type: 'VideoMontage',
|
|
2709
|
+
Operation: {
|
|
2710
|
+
TemplateId: videoMontageTemplate,
|
|
2711
|
+
Output: {
|
|
2712
|
+
Region: config.Region,
|
|
2713
|
+
Bucket: config.Bucket,
|
|
2714
|
+
Object: 'worlflow-test/${RunId}/montage.mp4',
|
|
2715
|
+
},
|
|
2716
|
+
},
|
|
2717
|
+
},
|
|
2718
|
+
SDRtoHDR_1581665960553: {
|
|
2719
|
+
Type: 'SDRtoHDR',
|
|
2720
|
+
Operation: {
|
|
2721
|
+
SDRtoHDR: {
|
|
2722
|
+
HdrMode: 'HLG',
|
|
2723
|
+
},
|
|
2724
|
+
TranscodeTemplateId: transcodeTemplate,
|
|
2725
|
+
WatermarkTemplateId: watermarkTemplate,
|
|
2726
|
+
Output: {
|
|
2727
|
+
Region: config.Region,
|
|
2728
|
+
Bucket: config.Bucket,
|
|
2729
|
+
Object: 'worlflow-test/${RunId}/SDRtoHDR.mp4',
|
|
2730
|
+
},
|
|
2731
|
+
},
|
|
2732
|
+
},
|
|
2733
|
+
VideoProcess_1581665960554: {
|
|
2734
|
+
Type: 'VideoProcess',
|
|
2735
|
+
Operation: {
|
|
2736
|
+
TemplateId: videoProcessTemplate,
|
|
2737
|
+
TranscodeTemplateId: transcodeTemplate,
|
|
2738
|
+
WatermarkTemplateId: watermarkTemplate,
|
|
2739
|
+
Output: {
|
|
2740
|
+
Region: config.Region,
|
|
2741
|
+
Bucket: config.Bucket,
|
|
2742
|
+
Object: 'worlflow-test/${RunId}/videoProcess.mp4',
|
|
2743
|
+
},
|
|
2744
|
+
},
|
|
2745
|
+
},
|
|
2746
|
+
SuperResolution_1581665960583: {
|
|
2747
|
+
Type: 'SuperResolution',
|
|
2748
|
+
Operation: {
|
|
2749
|
+
TemplateId: superResolutionTemplate,
|
|
2750
|
+
TranscodeTemplateId: transcodeTemplate,
|
|
2751
|
+
WatermarkTemplateId: watermarkTemplate,
|
|
2752
|
+
Output: {
|
|
2753
|
+
Region: config.Region,
|
|
2754
|
+
Bucket: config.Bucket,
|
|
2755
|
+
Object: 'worlflow-test/${RunId}/SuperResolution.mkv',
|
|
2756
|
+
},
|
|
2757
|
+
},
|
|
2758
|
+
},
|
|
2759
|
+
Segment_1581665960667: {
|
|
2760
|
+
Type: 'Segment',
|
|
2761
|
+
Operation: {
|
|
2762
|
+
Segment: {
|
|
2763
|
+
Format: 'mp4',
|
|
2764
|
+
Duration: '5',
|
|
2765
|
+
},
|
|
2766
|
+
Output: {
|
|
2767
|
+
Region: config.Region,
|
|
2768
|
+
Bucket: config.Bucket,
|
|
2769
|
+
Object: 'worlflow-test/${RunId}/segment-trans${Number}',
|
|
2770
|
+
},
|
|
2771
|
+
},
|
|
2772
|
+
},
|
|
2773
|
+
},
|
|
2774
|
+
},
|
|
2775
|
+
},
|
|
2776
|
+
},
|
|
2777
|
+
};
|
|
2778
|
+
cos.request(
|
|
2779
|
+
{
|
|
2780
|
+
Bucket: config.Bucket, // Bucket 格式:test-1250000000
|
|
2781
|
+
Region: config.Region,
|
|
2782
|
+
Method: 'POST',
|
|
2783
|
+
Key: 'workflow',
|
|
2784
|
+
Url: url,
|
|
2785
|
+
Headers: {
|
|
2786
|
+
'content-type': 'application/xml',
|
|
2787
|
+
},
|
|
2788
|
+
Body: json2xml(body),
|
|
2789
|
+
},
|
|
2790
|
+
function (err, data) {
|
|
2791
|
+
console.log(err || data);
|
|
2792
|
+
}
|
|
2793
|
+
);
|
|
2794
|
+
}
|
|
2795
|
+
|
|
2796
|
+
/**
|
|
2797
|
+
* 删除工作流
|
|
2798
|
+
*/
|
|
2799
|
+
function DeleteWorkflow() {
|
|
2800
|
+
let workflowId = 'wad8a9e26e1864a3793446fd9a686xxxx'; // 待删除的工作流ID
|
|
2801
|
+
let host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com';
|
|
2802
|
+
let url = 'https://' + host + '/workflow/' + workflowId;
|
|
2803
|
+
cos.request(
|
|
2804
|
+
{
|
|
2805
|
+
Bucket: config.Bucket, // Bucket 格式:test-1250000000
|
|
2806
|
+
Region: config.Region,
|
|
2807
|
+
Method: 'DELETE',
|
|
2808
|
+
Key: 'workflow/' + workflowId,
|
|
2809
|
+
Url: url,
|
|
2810
|
+
Headers: {
|
|
2811
|
+
'content-type': 'application/xml',
|
|
2812
|
+
},
|
|
2813
|
+
},
|
|
2814
|
+
function (err, data) {
|
|
2815
|
+
console.log(err || data);
|
|
2816
|
+
}
|
|
2817
|
+
);
|
|
2818
|
+
}
|
|
2819
|
+
|
|
2820
|
+
/**
|
|
2821
|
+
* 工作流列表
|
|
2822
|
+
*/
|
|
2823
|
+
function DescribeWorkflow() {
|
|
2824
|
+
let host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com';
|
|
2825
|
+
let url = 'https://' + host + '/workflow';
|
|
2826
|
+
cos.request(
|
|
2827
|
+
{
|
|
2828
|
+
Bucket: config.Bucket, // Bucket 格式:test-1250000000
|
|
2829
|
+
Region: config.Region,
|
|
2830
|
+
Method: 'GET',
|
|
2831
|
+
Key: 'workflow',
|
|
2832
|
+
Url: url,
|
|
2833
|
+
Query: {
|
|
2834
|
+
ids: '',
|
|
2835
|
+
},
|
|
2836
|
+
},
|
|
2837
|
+
function (err, data) {
|
|
2838
|
+
console.log(err || data);
|
|
2839
|
+
}
|
|
2840
|
+
);
|
|
2841
|
+
}
|
|
2842
|
+
|
|
2843
|
+
/**
|
|
2844
|
+
* 执行实例详情
|
|
2845
|
+
*/
|
|
2846
|
+
function DescribeWorkflowExecution() {
|
|
2847
|
+
let runId = 'ieed8aec4413a11ec913f52540003xxxx';
|
|
2848
|
+
let host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com';
|
|
2849
|
+
let url = 'https://' + host + '/workflowexecution/' + runId;
|
|
2850
|
+
cos.request(
|
|
2851
|
+
{
|
|
2852
|
+
Bucket: config.Bucket, // Bucket 格式:test-1250000000
|
|
2853
|
+
Region: config.Region,
|
|
2854
|
+
Method: 'GET',
|
|
2855
|
+
Key: 'workflowexecution/' + runId,
|
|
2856
|
+
Url: url,
|
|
2857
|
+
},
|
|
2858
|
+
function (err, data) {
|
|
2859
|
+
console.log(err || data);
|
|
2860
|
+
}
|
|
2861
|
+
);
|
|
2862
|
+
}
|
|
2863
|
+
|
|
2864
|
+
/**
|
|
2865
|
+
* 执行实例列表
|
|
2866
|
+
*/
|
|
2867
|
+
function DescribeWorkflowExecutions() {
|
|
2868
|
+
let workflowId = 'w093b29cfef824bd0922743a6f0afxxxx';
|
|
2869
|
+
let host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com';
|
|
2870
|
+
let url = 'https://' + host + '/workflowexecution';
|
|
2871
|
+
cos.request(
|
|
2872
|
+
{
|
|
2873
|
+
Bucket: config.Bucket, // Bucket 格式:test-1250000000
|
|
2874
|
+
Region: config.Region,
|
|
2875
|
+
Method: 'GET',
|
|
2876
|
+
Key: 'workflowexecution',
|
|
2877
|
+
Url: url,
|
|
2878
|
+
Query: {
|
|
2879
|
+
workflowId: workflowId,
|
|
2880
|
+
size: '3',
|
|
2881
|
+
states: 'Failed',
|
|
2882
|
+
},
|
|
2883
|
+
},
|
|
2884
|
+
function (err, data) {
|
|
2885
|
+
console.log(err || data);
|
|
2886
|
+
}
|
|
2887
|
+
);
|
|
2888
|
+
}
|
|
2889
|
+
|
|
2890
|
+
/**
|
|
2891
|
+
* 更新工作流配置
|
|
2892
|
+
*/
|
|
2893
|
+
function UpdateWorkflow() {
|
|
2894
|
+
let workflowId = 'w14404e66c27b4e0aafae6bc96acfxxxx';
|
|
2895
|
+
let queueId = 'p5ad1499214024af2bfaa4401d529xxxx';
|
|
2896
|
+
let callbackUrl = 'http://your.callback.com/index.php';
|
|
2897
|
+
let host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com';
|
|
2898
|
+
let url = 'https://' + host + '/workflow/' + workflowId;
|
|
2899
|
+
let body = {
|
|
2900
|
+
// 填上模版修改参数
|
|
2901
|
+
Request: {
|
|
2902
|
+
MediaWorkflow: {
|
|
2903
|
+
Name: 'test1',
|
|
2904
|
+
State: 'Active', // 创建并开启工作流
|
|
2905
|
+
Topology: {
|
|
2906
|
+
Dependencies: {
|
|
2907
|
+
Start: 'SmartCover_1581665960539',
|
|
2908
|
+
SmartCover_1581665960539: 'End',
|
|
2909
|
+
},
|
|
2910
|
+
Nodes: {
|
|
2911
|
+
Start: {
|
|
2912
|
+
Type: 'Start',
|
|
2913
|
+
Input: {
|
|
2914
|
+
QueueId: queueId,
|
|
2915
|
+
ObjectPrefix: 'test/',
|
|
2916
|
+
NotifyConfig: {
|
|
2917
|
+
Type: 'Url',
|
|
2918
|
+
Url: callbackUrl,
|
|
2919
|
+
Event: 'TaskFinish,WorkflowFinish',
|
|
2920
|
+
},
|
|
2921
|
+
ExtFilter: {
|
|
2922
|
+
State: 'On',
|
|
2923
|
+
Video: 'true',
|
|
2924
|
+
Custom: 'true',
|
|
2925
|
+
CustomExts: 'mp4/mp3',
|
|
2926
|
+
AllFile: 'false',
|
|
2927
|
+
},
|
|
2928
|
+
},
|
|
2929
|
+
},
|
|
2930
|
+
SmartCover_1581665960539: {
|
|
2931
|
+
Type: 'SmartCover',
|
|
2932
|
+
Operation: {
|
|
2933
|
+
Output: {
|
|
2934
|
+
Region: config.Region,
|
|
2935
|
+
Bucket: config.Bucket,
|
|
2936
|
+
Object: 'worlflow-test/${RunId}/cover-${Number}.jpg',
|
|
2937
|
+
},
|
|
2938
|
+
SmartCover: {
|
|
2939
|
+
Format: 'png',
|
|
2940
|
+
Width: '128',
|
|
2941
|
+
Height: '128',
|
|
2942
|
+
Count: '3',
|
|
2943
|
+
DeleteDuplicates: 'false',
|
|
2944
|
+
},
|
|
2945
|
+
},
|
|
2946
|
+
},
|
|
2947
|
+
},
|
|
2948
|
+
},
|
|
2949
|
+
},
|
|
2950
|
+
},
|
|
2951
|
+
};
|
|
2952
|
+
cos.request(
|
|
2953
|
+
{
|
|
2954
|
+
Bucket: config.Bucket, // Bucket 格式:test-1250000000
|
|
2955
|
+
Region: config.Region,
|
|
2956
|
+
Method: 'PUT',
|
|
2957
|
+
Key: 'workflow/' + workflowId,
|
|
2958
|
+
Url: url,
|
|
2959
|
+
Headers: {
|
|
2960
|
+
'content-type': 'application/xml',
|
|
2961
|
+
},
|
|
2962
|
+
Body: json2xml(body),
|
|
2963
|
+
},
|
|
2964
|
+
function (err, data) {
|
|
2965
|
+
console.log(err || data);
|
|
2966
|
+
}
|
|
2967
|
+
);
|
|
2968
|
+
}
|
|
2969
|
+
|
|
2970
|
+
/**
|
|
2971
|
+
* 触发工作流
|
|
2972
|
+
*/
|
|
2973
|
+
function TriggerWorkflow() {
|
|
2974
|
+
let workflowId = 'w093b29cfef824bd0922743a6f0afxxxx';
|
|
2975
|
+
let host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com';
|
|
2976
|
+
let url = 'https://' + host + '/triggerworkflow';
|
|
2977
|
+
cos.request(
|
|
2978
|
+
{
|
|
2979
|
+
Bucket: config.Bucket, // Bucket 格式:test-1250000000
|
|
2980
|
+
Region: config.Region,
|
|
2981
|
+
Method: 'POST',
|
|
2982
|
+
Key: 'triggerworkflow',
|
|
2983
|
+
Url: url,
|
|
2984
|
+
Headers: {
|
|
2985
|
+
'content-type': 'application/xml',
|
|
2986
|
+
},
|
|
2987
|
+
Query: {
|
|
2988
|
+
workflowId: workflowId,
|
|
2989
|
+
object: 'test.mp4',
|
|
2990
|
+
},
|
|
2991
|
+
},
|
|
2992
|
+
function (err, data) {
|
|
2993
|
+
console.log(err || data);
|
|
2994
|
+
}
|
|
2995
|
+
);
|
|
2996
|
+
}
|
|
2997
|
+
|
|
2998
|
+
// 同步审核存储桶里的图片对象
|
|
2999
|
+
function SyncAuditImageObject() {
|
|
3000
|
+
cos.request(
|
|
3001
|
+
{
|
|
3002
|
+
Bucket: config.Bucket, // Bucket 格式:test-1250000000
|
|
3003
|
+
Region: config.Region,
|
|
3004
|
+
Key: 'audit/1.jpg',
|
|
3005
|
+
Method: 'GET',
|
|
3006
|
+
Query: {
|
|
3007
|
+
'ci-process': 'sensitive-content-recognition',
|
|
3008
|
+
// 'detect-url': '<url>',
|
|
3009
|
+
'biz-type': '', // 审核策略 id
|
|
3010
|
+
// 'interval': 5, // gif截取间隔帧数
|
|
3011
|
+
// 'max-frames': 5, // gif最大截帧数
|
|
3012
|
+
},
|
|
3013
|
+
},
|
|
3014
|
+
function (err, data) {
|
|
3015
|
+
console.log(err || data);
|
|
3016
|
+
}
|
|
3017
|
+
);
|
|
3018
|
+
}
|
|
3019
|
+
|
|
3020
|
+
/**
|
|
3021
|
+
* 获取私有 M3U8 ts 资源的下载授权
|
|
3022
|
+
*/
|
|
3023
|
+
function GetPrivateM3U8() {
|
|
3024
|
+
cos.request(
|
|
3025
|
+
{
|
|
3026
|
+
Bucket: config.Bucket, // Bucket 格式:test-1250000000
|
|
3027
|
+
Region: config.Region,
|
|
3028
|
+
Method: 'GET',
|
|
3029
|
+
Key: 'test.m3u8',
|
|
3030
|
+
Query: {
|
|
3031
|
+
'ci-process': 'pm3u8',
|
|
3032
|
+
expires: '3600',
|
|
3033
|
+
},
|
|
3034
|
+
},
|
|
3035
|
+
function (err, data) {
|
|
3036
|
+
console.log(err || data);
|
|
3037
|
+
}
|
|
3038
|
+
);
|
|
3039
|
+
}
|
|
3040
|
+
|
|
3041
|
+
// 同步审核任意图片 Url
|
|
3042
|
+
function SyncAuditImageUrl() {
|
|
3043
|
+
cos.request(
|
|
3044
|
+
{
|
|
3045
|
+
Bucket: config.Bucket, // Bucket 格式:test-1250000000
|
|
3046
|
+
Region: config.Region,
|
|
3047
|
+
Method: 'GET',
|
|
3048
|
+
Query: {
|
|
3049
|
+
'ci-process': 'sensitive-content-recognition',
|
|
3050
|
+
'detect-url': 'https://ftp.bmp.ovh/imgs/2021/09/ee4e63607465ed8d.jpg',
|
|
3051
|
+
// 'biz-type': '<type>', // 审核策略 id
|
|
3052
|
+
// 'interval': 5, // gif截取间隔帧数
|
|
3053
|
+
// 'max-frames': 5, // gif最大截帧数
|
|
3054
|
+
},
|
|
3055
|
+
},
|
|
3056
|
+
function (err, data) {
|
|
3057
|
+
console.log(err || data);
|
|
3058
|
+
}
|
|
3059
|
+
);
|
|
3060
|
+
}
|
|
3061
|
+
|
|
3062
|
+
// 批量同步审核任意图片 Url
|
|
3063
|
+
function SyncAuditImageUrls() {
|
|
3064
|
+
cos.request(
|
|
3065
|
+
{
|
|
3066
|
+
Url: `https://${config.Bucket}.ci.${config.Region}.myqcloud.com/image/auditing`,
|
|
3067
|
+
Method: 'POST',
|
|
3068
|
+
Headers: {
|
|
3069
|
+
'content-type': 'application/xml',
|
|
3070
|
+
},
|
|
3071
|
+
Body: json2xml({
|
|
3072
|
+
Request: {
|
|
3073
|
+
Input: [
|
|
3074
|
+
{
|
|
3075
|
+
Object: 'audit/1.jpg',
|
|
3076
|
+
// DataId: '1', // 审核序号
|
|
3077
|
+
// Url: '<url>',
|
|
3078
|
+
// Interval: 5,
|
|
3079
|
+
// MaxFrames: 5,
|
|
3080
|
+
},
|
|
3081
|
+
{
|
|
3082
|
+
Object: 'audit/2.jpg',
|
|
3083
|
+
},
|
|
3084
|
+
],
|
|
3085
|
+
Conf: {
|
|
3086
|
+
// Callback: '<url>', // 回调地址
|
|
3087
|
+
BizType: '', // 审核策略
|
|
3088
|
+
},
|
|
3089
|
+
},
|
|
3090
|
+
}),
|
|
3091
|
+
},
|
|
3092
|
+
function (err, data) {
|
|
3093
|
+
console.log(err || data.Response.JobsDetail);
|
|
3094
|
+
}
|
|
3095
|
+
);
|
|
3096
|
+
}
|
|
3097
|
+
|
|
3098
|
+
// 审核文本内容
|
|
3099
|
+
function SyncAuditTextContent() {
|
|
3100
|
+
cos.request(
|
|
3101
|
+
{
|
|
3102
|
+
Url: `https://${config.Bucket}.ci.${config.Region}.myqcloud.com/text/auditing`,
|
|
3103
|
+
Method: 'POST',
|
|
3104
|
+
Headers: {
|
|
3105
|
+
'content-type': 'application/xml',
|
|
3106
|
+
},
|
|
3107
|
+
Body: json2xml({
|
|
3108
|
+
Request: {
|
|
3109
|
+
Input: {
|
|
3110
|
+
Content: Buffer.from('高潮').toString('base64'),
|
|
3111
|
+
},
|
|
3112
|
+
Conf: {
|
|
3113
|
+
// Callback: '<url>', // 回调地址
|
|
3114
|
+
BizType: '', // 审核策略
|
|
3115
|
+
},
|
|
3116
|
+
},
|
|
3117
|
+
}),
|
|
3118
|
+
},
|
|
3119
|
+
function (err, data) {
|
|
3120
|
+
console.log(err || data.Response.JobsDetail);
|
|
3121
|
+
}
|
|
3122
|
+
);
|
|
3123
|
+
}
|
|
3124
|
+
|
|
3125
|
+
// 提交图片审核任务
|
|
3126
|
+
function CreateAuditJob() {
|
|
3127
|
+
var objectKey = 'audit/1.jpg';
|
|
3128
|
+
var objectType = 'image'; // image/audio/video/text/document
|
|
3129
|
+
cos.request(
|
|
3130
|
+
{
|
|
3131
|
+
Url: `https://${config.Bucket}.ci.${config.Region}.myqcloud.com/${objectType}/auditing`,
|
|
3132
|
+
Method: 'POST',
|
|
3133
|
+
Headers: {
|
|
3134
|
+
'content-type': 'application/xml',
|
|
3135
|
+
},
|
|
3136
|
+
Body: json2xml({
|
|
3137
|
+
Request: {
|
|
3138
|
+
Input: {
|
|
3139
|
+
Object: objectKey,
|
|
3140
|
+
},
|
|
3141
|
+
Conf: {
|
|
3142
|
+
// Callback: '<url>', // 回调地址
|
|
3143
|
+
BizType: '', // 审核策略
|
|
3144
|
+
},
|
|
3145
|
+
},
|
|
3146
|
+
}),
|
|
3147
|
+
},
|
|
3148
|
+
function (err, data) {
|
|
3149
|
+
console.log(err || data.Response.JobsDetail);
|
|
3150
|
+
}
|
|
3151
|
+
);
|
|
3152
|
+
}
|
|
3153
|
+
|
|
3154
|
+
// 查询审核任务结果
|
|
3155
|
+
function DescribeAuditJob() {
|
|
3156
|
+
var jobId = 'st3bb560af647911ec919652540024deb5';
|
|
3157
|
+
cos.request(
|
|
3158
|
+
{
|
|
3159
|
+
Url: `https://${config.Bucket}.ci.${config.Region}.myqcloud.com/text/auditing/${jobId}`,
|
|
3160
|
+
Method: 'GET',
|
|
3161
|
+
},
|
|
3162
|
+
function (err, data) {
|
|
3163
|
+
console.log(err || data.Response.JobsDetail);
|
|
3164
|
+
}
|
|
3165
|
+
);
|
|
3166
|
+
}
|
|
3167
|
+
|
|
3168
|
+
// 提交直播审核任务
|
|
3169
|
+
function postLiveAuditing() {
|
|
3170
|
+
var host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com';
|
|
3171
|
+
var url = 'https://' + host + '/video/auditing';
|
|
3172
|
+
var body = COS.util.json2xml({
|
|
3173
|
+
Request: {
|
|
3174
|
+
Type: 'live_video',
|
|
3175
|
+
Input: {
|
|
3176
|
+
Url: 'rtmp://example.com/live/123', // 需要审核的直播流播放地址
|
|
3177
|
+
// DataId: '',
|
|
3178
|
+
// UserInfo: {},
|
|
3179
|
+
},
|
|
3180
|
+
Conf: {
|
|
3181
|
+
BizType: '766d07a7af937c26216c51db29793ea6',
|
|
3182
|
+
// Callback: 'https://callback.com', // 回调地址,非必须
|
|
3183
|
+
// CallbackType: 1, // 回调片段类型,非必须
|
|
3184
|
+
},
|
|
3185
|
+
},
|
|
3186
|
+
});
|
|
3187
|
+
cos.request(
|
|
3188
|
+
{
|
|
3189
|
+
Bucket: config.Bucket,
|
|
3190
|
+
Region: config.Region,
|
|
3191
|
+
Method: 'POST',
|
|
3192
|
+
Url: url,
|
|
3193
|
+
Key: '/video/auditing',
|
|
3194
|
+
ContentType: 'application/xml',
|
|
3195
|
+
Body: body,
|
|
3196
|
+
},
|
|
3197
|
+
function (err, data) {
|
|
3198
|
+
console.log(err || data);
|
|
3199
|
+
}
|
|
3200
|
+
);
|
|
3201
|
+
}
|
|
3202
|
+
|
|
3203
|
+
// 查询直播审核任务结果
|
|
3204
|
+
function getLiveAuditingResult() {
|
|
3205
|
+
var jobId = 'av99005f3ebd8911edb05a52540084c07b'; // jobId可以通过提交直播审核任务返回
|
|
3206
|
+
var host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com';
|
|
3207
|
+
var url = 'https://' + host + '/video/auditing/' + jobId;
|
|
3208
|
+
cos.request(
|
|
3209
|
+
{
|
|
3210
|
+
Bucket: config.Bucket,
|
|
3211
|
+
Region: config.Region,
|
|
3212
|
+
Method: 'GET',
|
|
3213
|
+
Key: '/video/auditing/' + jobId,
|
|
3214
|
+
Url: url,
|
|
3215
|
+
},
|
|
3216
|
+
function (err, data) {
|
|
3217
|
+
console.log(err || data);
|
|
3218
|
+
}
|
|
3219
|
+
);
|
|
3220
|
+
}
|
|
3221
|
+
|
|
3222
|
+
// 提交病毒检测任务
|
|
3223
|
+
function postVirusDetect() {
|
|
3224
|
+
var host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com/virus/detect';
|
|
3225
|
+
var url = 'https://' + host;
|
|
3226
|
+
var body = COS.util.json2xml({
|
|
3227
|
+
Request: {
|
|
3228
|
+
Input: {
|
|
3229
|
+
Object: 'test/1.png', // 文件名,取值为文件在当前存储桶中的完整名称,与Url参数二选一
|
|
3230
|
+
// Url: 'http://examplebucket-1250000000.cos.ap-shanghai.myqcloud.com/virus.doc', // 病毒文件的链接地址,与Object参数二选一
|
|
3231
|
+
},
|
|
3232
|
+
Conf: {
|
|
3233
|
+
DetectType: 'Virus', // 检测的病毒类型,当前固定为:Virus
|
|
3234
|
+
// CallBack: 'http://callback.demo.com', // 任务回调的地址
|
|
3235
|
+
},
|
|
3236
|
+
},
|
|
3237
|
+
});
|
|
3238
|
+
cos.request(
|
|
3239
|
+
{
|
|
3240
|
+
Method: 'POST',
|
|
3241
|
+
Key: 'virus/detect',
|
|
3242
|
+
Url: url,
|
|
3243
|
+
Body: body,
|
|
3244
|
+
ContentType: 'application/xml',
|
|
3245
|
+
},
|
|
3246
|
+
function (err, data) {
|
|
3247
|
+
console.log(err || data);
|
|
3248
|
+
}
|
|
3249
|
+
);
|
|
3250
|
+
}
|
|
3251
|
+
|
|
3252
|
+
// 查询病毒检测任务结果
|
|
3253
|
+
function getVirusDetectResult() {
|
|
3254
|
+
var jobId = 'ssc6df8d13bd8911ed904c525400941127'; // 提交病毒检测任务后会返回当前任务的jobId
|
|
3255
|
+
var host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com/virus/detect/' + jobId;
|
|
3256
|
+
var url = 'https://' + host;
|
|
3257
|
+
cos.request(
|
|
3258
|
+
{
|
|
3259
|
+
Method: 'GET',
|
|
3260
|
+
Key: 'virus/detect/' + jobId,
|
|
3261
|
+
Url: url,
|
|
3262
|
+
},
|
|
3263
|
+
function (err, data) {
|
|
3264
|
+
console.log(err || data);
|
|
3265
|
+
}
|
|
3266
|
+
);
|
|
3267
|
+
}
|
|
3268
|
+
|
|
3269
|
+
// 提交音频降噪任务
|
|
3270
|
+
function postNoiseReduction() {
|
|
3271
|
+
var host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com/jobs';
|
|
3272
|
+
var url = 'https://' + host;
|
|
3273
|
+
var body = COS.util.json2xml({
|
|
3274
|
+
Request: {
|
|
3275
|
+
Tag: 'NoiseReduction',
|
|
3276
|
+
Input: {
|
|
3277
|
+
Object: 'ci/music.mp3', // 文件名,取值为文件在当前存储桶中的完整名称
|
|
3278
|
+
},
|
|
3279
|
+
Operation: {
|
|
3280
|
+
Output: {
|
|
3281
|
+
Bucket: config.Bucket, // 输出的存储桶
|
|
3282
|
+
Region: config.Region, // 输出的存储桶的地域
|
|
3283
|
+
Object: 'ci/out.mp3', // 输出的文件Key
|
|
3284
|
+
},
|
|
3285
|
+
},
|
|
3286
|
+
// QueueId: '', // 任务所在的队列 ID,非必须
|
|
3287
|
+
// CallBackFormat: '', // 任务回调格式,JSON 或 XML,默认 XML,优先级高于队列的回调格式,非必须
|
|
3288
|
+
// CallBackType: '', // 任务回调类型,Url 或 TDMQ,默认 Url,优先级高于队列的回调类型,非必须
|
|
3289
|
+
// CallBack: '', // 任务回调地址,优先级高于队列的回调地址。设置为 no 时,表示队列的回调地址不产生回调,非必须
|
|
3290
|
+
// CallBackMqConfig: '', // 任务回调 TDMQ 配置,当 CallBackType 为 TDMQ 时必填,非必须
|
|
3291
|
+
},
|
|
3292
|
+
});
|
|
3293
|
+
cos.request(
|
|
3294
|
+
{
|
|
3295
|
+
Method: 'POST',
|
|
3296
|
+
Key: 'jobs',
|
|
3297
|
+
Url: url,
|
|
3298
|
+
Body: body,
|
|
3299
|
+
ContentType: 'application/xml',
|
|
3300
|
+
},
|
|
3301
|
+
function (err, data) {
|
|
3302
|
+
console.log(err || data);
|
|
3303
|
+
}
|
|
3304
|
+
);
|
|
3305
|
+
}
|
|
3306
|
+
|
|
3307
|
+
// 提交人声分离任务
|
|
3308
|
+
function postVoiceSeparate() {
|
|
3309
|
+
var host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com/jobs';
|
|
3310
|
+
var url = 'https://' + host;
|
|
3311
|
+
var body = COS.util.json2xml({
|
|
3312
|
+
Request: {
|
|
3313
|
+
Tag: 'VoiceSeparate',
|
|
3314
|
+
Input: {
|
|
3315
|
+
Object: 'ci/music.mp3', // 文件名,取值为文件在当前存储桶中的完整名称
|
|
3316
|
+
},
|
|
3317
|
+
Operation: {
|
|
3318
|
+
// VoiceSeparate: {}, // 指定转码模板参数,非必须
|
|
3319
|
+
TemplateId: 't13fca82ad97e84878a22cd81bd2e5652c', // 指定的模板 ID,必须
|
|
3320
|
+
// JobLevel: 0, // 任务优先级,级别限制:0 、1 、2。级别越大任务优先级越高,默认为0,非必须
|
|
3321
|
+
Output: {
|
|
3322
|
+
Bucket: config.Bucket, // 输出的存储桶
|
|
3323
|
+
Region: config.Region, // 输出的存储桶的地域
|
|
3324
|
+
Object: 'ci/out/background.mp3', // 输出的文件Key,背景音结果文件名,不能与 AuObject 同时为空
|
|
3325
|
+
AuObject: 'ci/out/audio.mp3',
|
|
3326
|
+
},
|
|
3327
|
+
},
|
|
3328
|
+
// QueueId: '', // 任务所在的队列 ID,非必须
|
|
3329
|
+
// CallBackFormat: '', // 任务回调格式,JSON 或 XML,默认 XML,优先级高于队列的回调格式,非必须
|
|
3330
|
+
// CallBackType: '', // 任务回调类型,Url 或 TDMQ,默认 Url,优先级高于队列的回调类型,非必须
|
|
3331
|
+
// CallBack: '', // 任务回调地址,优先级高于队列的回调地址。设置为 no 时,表示队列的回调地址不产生回调,非必须
|
|
3332
|
+
// CallBackMqConfig: '', // 任务回调 TDMQ 配置,当 CallBackType 为 TDMQ 时必填,非必须
|
|
3333
|
+
},
|
|
3334
|
+
});
|
|
3335
|
+
cos.request(
|
|
3336
|
+
{
|
|
3337
|
+
Method: 'POST',
|
|
3338
|
+
Key: 'jobs',
|
|
3339
|
+
Url: url,
|
|
3340
|
+
Body: body,
|
|
3341
|
+
ContentType: 'application/xml',
|
|
3342
|
+
},
|
|
3343
|
+
function (err, data) {
|
|
3344
|
+
console.log(err || data);
|
|
3345
|
+
}
|
|
3346
|
+
);
|
|
3347
|
+
}
|
|
3348
|
+
|
|
3349
|
+
// 提交语音合成任务
|
|
3350
|
+
function postTts() {
|
|
3351
|
+
var host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com/jobs';
|
|
3352
|
+
var url = 'https://' + host;
|
|
3353
|
+
var body = COS.util.json2xml({
|
|
3354
|
+
Request: {
|
|
3355
|
+
Tag: 'Tts',
|
|
3356
|
+
Operation: {
|
|
3357
|
+
// VoiceSeparate: {}, // 指定转码模板参数,非必须
|
|
3358
|
+
TemplateId: 't192931b3564084168a3f50ebfea59acb3', // 指定的模板 ID,必须
|
|
3359
|
+
// JobLevel: 0, // 任务优先级,级别限制:0 、1 、2。级别越大任务优先级越高,默认为0,非必须
|
|
3360
|
+
TtsConfig: {
|
|
3361
|
+
InputType: 'Text',
|
|
3362
|
+
Input: '床前明月光,疑是地上霜',
|
|
3363
|
+
},
|
|
3364
|
+
Output: {
|
|
3365
|
+
Bucket: config.Bucket, // 输出的存储桶
|
|
3366
|
+
Region: config.Region, // 输出的存储桶的地域
|
|
3367
|
+
Object: 'ci/out/tts.mp3', // 输出的文件Key
|
|
3368
|
+
},
|
|
3369
|
+
},
|
|
3370
|
+
// QueueId: '', // 任务所在的队列 ID,非必须
|
|
3371
|
+
// CallBackFormat: '', // 任务回调格式,JSON 或 XML,默认 XML,优先级高于队列的回调格式,非必须
|
|
3372
|
+
// CallBackType: '', // 任务回调类型,Url 或 TDMQ,默认 Url,优先级高于队列的回调类型,非必须
|
|
3373
|
+
// CallBack: '', // 任务回调地址,优先级高于队列的回调地址。设置为 no 时,表示队列的回调地址不产生回调,非必须
|
|
3374
|
+
// CallBackMqConfig: '', // 任务回调 TDMQ 配置,当 CallBackType 为 TDMQ 时必填,非必须
|
|
3375
|
+
},
|
|
3376
|
+
});
|
|
3377
|
+
cos.request(
|
|
3378
|
+
{
|
|
3379
|
+
Method: 'POST',
|
|
3380
|
+
Key: 'jobs',
|
|
3381
|
+
Url: url,
|
|
3382
|
+
Body: body,
|
|
3383
|
+
ContentType: 'application/xml',
|
|
3384
|
+
},
|
|
3385
|
+
function (err, data) {
|
|
3386
|
+
console.log(err || data);
|
|
3387
|
+
}
|
|
3388
|
+
);
|
|
3389
|
+
}
|
|
3390
|
+
|
|
3391
|
+
// 提交语音识别任务
|
|
3392
|
+
function postSpeechRecognition() {
|
|
3393
|
+
var host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com/asr_jobs';
|
|
3394
|
+
var url = 'https://' + host;
|
|
3395
|
+
var body = COS.util.json2xml({
|
|
3396
|
+
Request: {
|
|
3397
|
+
Tag: 'SpeechRecognition',
|
|
3398
|
+
Input: {
|
|
3399
|
+
Object: 'ci/music.mp3', // 文件名,取值为文件在当前存储桶中的完整名称,与Url参数二选一
|
|
3400
|
+
// Url: 'http://examplebucket-1250000000.cos.ap-shanghai.myqcloud.com/music.mp3', // 病毒文件的链接地址,与Object参数二选一
|
|
3401
|
+
},
|
|
3402
|
+
Operation: {
|
|
3403
|
+
SpeechRecognition: {
|
|
3404
|
+
EngineModelType: '16k_zh_video', // 引擎模型类型
|
|
3405
|
+
ChannelNum: 1, // 语音声道数
|
|
3406
|
+
ResTextFormat: 0, // 识别结果返回形式
|
|
3407
|
+
FilterDirty: 1, // 是否过滤脏词(目前支持中文普通话引擎)
|
|
3408
|
+
FilterModal: 1, // 是否过语气词(目前支持中文普通话引擎)
|
|
3409
|
+
ConvertNumMode: 0, // 是否进行阿拉伯数字智能转换(目前支持中文普通话引擎)
|
|
3410
|
+
},
|
|
3411
|
+
Output: {
|
|
3412
|
+
Bucket: config.Bucket, // 输出的存储桶
|
|
3413
|
+
Region: config.Region, // 输出的存储桶的地域
|
|
3414
|
+
Object: 'ci/out/SpeechRecognition.mp3', // 输出的文件Key
|
|
3415
|
+
},
|
|
3416
|
+
},
|
|
3417
|
+
// QueueId: '', // 任务所在的队列 ID,非必须
|
|
3418
|
+
// CallBackFormat: '', // 任务回调格式,JSON 或 XML,默认 XML,优先级高于队列的回调格式,非必须
|
|
3419
|
+
// CallBackType: '', // 任务回调类型,Url 或 TDMQ,默认 Url,优先级高于队列的回调类型,非必须
|
|
3420
|
+
// CallBack: '', // 任务回调地址,优先级高于队列的回调地址。设置为 no 时,表示队列的回调地址不产生回调,非必须
|
|
3421
|
+
// CallBackMqConfig: '', // 任务回调 TDMQ 配置,当 CallBackType 为 TDMQ 时必填,非必须
|
|
3422
|
+
},
|
|
3423
|
+
});
|
|
3424
|
+
cos.request(
|
|
3425
|
+
{
|
|
3426
|
+
Method: 'POST',
|
|
3427
|
+
Key: 'asr_jobs',
|
|
3428
|
+
Url: url,
|
|
3429
|
+
Body: body,
|
|
3430
|
+
ContentType: 'application/xml',
|
|
3431
|
+
},
|
|
3432
|
+
function (err, data) {
|
|
3433
|
+
console.log(err || data);
|
|
3434
|
+
}
|
|
3435
|
+
);
|
|
3436
|
+
}
|
|
3437
|
+
|
|
3438
|
+
// 查询语音识别队列
|
|
3439
|
+
function getAsrQueue() {
|
|
3440
|
+
var host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com/asrqueue';
|
|
3441
|
+
var url = 'https://' + host;
|
|
3442
|
+
cos.request(
|
|
3443
|
+
{
|
|
3444
|
+
Method: 'GET',
|
|
3445
|
+
Key: 'asrqueue',
|
|
3446
|
+
Url: url,
|
|
3447
|
+
Query: {
|
|
3448
|
+
// queueIds: '', /* 非必须,队列 ID,以“,”符号分割字符串 */
|
|
3449
|
+
// state: '', /* 非必须,1=Active,2=Paused */
|
|
3450
|
+
// pageNumber: 1, /* 非必须,第几页 */
|
|
3451
|
+
// pageSize: 2, /* 非必须,每页个数 */
|
|
3452
|
+
},
|
|
3453
|
+
},
|
|
3454
|
+
function (err, data) {
|
|
3455
|
+
console.log(err || data);
|
|
3456
|
+
}
|
|
3457
|
+
);
|
|
3458
|
+
}
|
|
3459
|
+
|
|
3460
|
+
// 更新语音识别队列
|
|
3461
|
+
function putAsrQueue() {
|
|
3462
|
+
// 任务所在的队列 ID,请使用查询队列(https://cloud.tencent.com/document/product/460/46946)获取或前往万象控制台(https://cloud.tencent.com/document/product/460/46487)在存储桶中查询
|
|
3463
|
+
var queueId = 'pcc77499e85c311edb9865254008618d9';
|
|
3464
|
+
var host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com/asrqueue/' + queueId;
|
|
3465
|
+
var url = 'https://' + host;
|
|
3466
|
+
var body = COS.util.json2xml({
|
|
3467
|
+
Request: {
|
|
3468
|
+
Name: 'queue-doc-process-1',
|
|
3469
|
+
QueueID: queueId,
|
|
3470
|
+
State: 'Paused',
|
|
3471
|
+
NotifyConfig: {
|
|
3472
|
+
// Url: '',
|
|
3473
|
+
// Type: 'Url',
|
|
3474
|
+
// Event: '',
|
|
3475
|
+
State: 'Off',
|
|
3476
|
+
},
|
|
3477
|
+
},
|
|
3478
|
+
});
|
|
3479
|
+
cos.request(
|
|
3480
|
+
{
|
|
3481
|
+
Method: 'PUT',
|
|
3482
|
+
Key: 'asrqueue/' + queueId,
|
|
3483
|
+
Url: url,
|
|
3484
|
+
Body: body,
|
|
3485
|
+
ContentType: 'application/xml',
|
|
3486
|
+
},
|
|
3487
|
+
function (err, data) {
|
|
3488
|
+
console.log(err || data);
|
|
3489
|
+
}
|
|
3490
|
+
);
|
|
3491
|
+
}
|
|
3492
|
+
|
|
3493
|
+
// 查询语音识别开通状态
|
|
3494
|
+
function getAsrBucket() {
|
|
3495
|
+
var host = 'ci.' + config.Region + '.myqcloud.com/asrbucket';
|
|
3496
|
+
var url = 'https://' + host;
|
|
3497
|
+
cos.request(
|
|
3498
|
+
{
|
|
3499
|
+
Method: 'GET',
|
|
3500
|
+
Key: 'asrbucket',
|
|
3501
|
+
Url: url,
|
|
3502
|
+
Query: {
|
|
3503
|
+
// regions: '', /* 非必须,地域信息,以“,”分隔字符串,支持 All、ap-shanghai、ap-beijing */
|
|
3504
|
+
// bucketNames: '', /* 非必须,存储桶名称,以“,”分隔,支持多个存储桶,精确搜索 */
|
|
3505
|
+
// bucketName: '', /* 非必须,存储桶名称前缀,前缀搜索 */
|
|
3506
|
+
// pageNumber: 1, /* 非必须,第几页 */
|
|
3507
|
+
// pageSize: 10, /* 非必须,每页个数 */
|
|
3508
|
+
},
|
|
3509
|
+
},
|
|
3510
|
+
function (err, data) {
|
|
3511
|
+
console.log(err || data);
|
|
3512
|
+
}
|
|
3513
|
+
);
|
|
3514
|
+
}
|
|
3515
|
+
|
|
3516
|
+
// 设置防盗链
|
|
3517
|
+
function setRefer() {
|
|
3518
|
+
var host = config.Bucket + '.pic.' + config.Region + '.myqcloud.com/?hotlink';
|
|
3519
|
+
var url = 'https://' + host;
|
|
3520
|
+
var body = COS.util.json2xml({
|
|
3521
|
+
Hotlink: {
|
|
3522
|
+
Url: 'https://www.example.com', // 必须,域名地址
|
|
3523
|
+
Type: 'white', // 必须,防盗链类型,white 为白名单,black 为黑名单,off 为关闭。
|
|
3524
|
+
},
|
|
3525
|
+
});
|
|
3526
|
+
cos.request(
|
|
3527
|
+
{
|
|
3528
|
+
Method: 'PUT',
|
|
3529
|
+
Url: url,
|
|
3530
|
+
Body: body,
|
|
3531
|
+
ContentType: 'application/xml',
|
|
3532
|
+
},
|
|
3533
|
+
function (err, data) {
|
|
3534
|
+
console.log(err || data);
|
|
3535
|
+
}
|
|
3536
|
+
);
|
|
3537
|
+
}
|
|
3538
|
+
|
|
3539
|
+
// 查询防盗链
|
|
3540
|
+
function describeRefer() {
|
|
3541
|
+
var host = config.Bucket + '.pic.' + config.Region + '.myqcloud.com/?hotlink';
|
|
3542
|
+
var url = 'https://' + host;
|
|
3543
|
+
cos.request(
|
|
3544
|
+
{
|
|
3545
|
+
Method: 'GET',
|
|
3546
|
+
Url: url,
|
|
3547
|
+
},
|
|
3548
|
+
function (err, data) {
|
|
3549
|
+
console.log(err || data);
|
|
3550
|
+
}
|
|
3551
|
+
);
|
|
3552
|
+
}
|
|
3553
|
+
|
|
3554
|
+
// 开通原图保护
|
|
3555
|
+
function openOriginProtect() {
|
|
3556
|
+
var host = config.Bucket + '.pic.' + config.Region + '.myqcloud.com/?origin-protect';
|
|
3557
|
+
var url = 'https://' + host;
|
|
3558
|
+
cos.request(
|
|
3559
|
+
{
|
|
3560
|
+
Method: 'PUT',
|
|
3561
|
+
Url: url,
|
|
3562
|
+
},
|
|
3563
|
+
function (err, data) {
|
|
3564
|
+
console.log(err || data);
|
|
3565
|
+
}
|
|
3566
|
+
);
|
|
3567
|
+
}
|
|
3568
|
+
|
|
3569
|
+
// 查询原图保护状态
|
|
3570
|
+
function describeOriginProtect() {
|
|
3571
|
+
var host = config.Bucket + '.pic.' + config.Region + '.myqcloud.com/?origin-protect';
|
|
3572
|
+
var url = 'https://' + host;
|
|
3573
|
+
cos.request(
|
|
3574
|
+
{
|
|
3575
|
+
Method: 'GET',
|
|
3576
|
+
Url: url,
|
|
3577
|
+
},
|
|
3578
|
+
function (err, data) {
|
|
3579
|
+
console.log(err || data);
|
|
3580
|
+
}
|
|
3581
|
+
);
|
|
3582
|
+
}
|
|
3583
|
+
|
|
3584
|
+
// 关闭原图保护
|
|
3585
|
+
function closeOriginProtect() {
|
|
3586
|
+
var host = config.Bucket + '.pic.' + config.Region + '.myqcloud.com/?origin-protect';
|
|
3587
|
+
var url = 'https://' + host;
|
|
3588
|
+
cos.request(
|
|
3589
|
+
{
|
|
3590
|
+
Method: 'DELETE',
|
|
3591
|
+
Url: url,
|
|
3592
|
+
},
|
|
3593
|
+
function (err, data) {
|
|
3594
|
+
console.log(err || data);
|
|
3595
|
+
}
|
|
3596
|
+
);
|
|
3597
|
+
}
|
|
3598
|
+
|
|
3599
|
+
// 图片样式 - 增加样式
|
|
3600
|
+
function addImageStyle() {
|
|
3601
|
+
var host = config.Bucket + '.pic.' + config.Region + '.myqcloud.com/?style';
|
|
3602
|
+
var url = 'https://' + host;
|
|
3603
|
+
var body = COS.util.json2xml({
|
|
3604
|
+
AddStyle: {
|
|
3605
|
+
StyleName: 'style_name1', // 必须,样式名称
|
|
3606
|
+
StyleBody: 'imageMogr2/thumbnail/!50px', // 必须,样式详情
|
|
3607
|
+
},
|
|
3608
|
+
});
|
|
3609
|
+
cos.request(
|
|
3610
|
+
{
|
|
3611
|
+
Method: 'PUT',
|
|
3612
|
+
Url: url,
|
|
3613
|
+
Body: body,
|
|
3614
|
+
ContentType: 'application/xml',
|
|
3615
|
+
},
|
|
3616
|
+
function (err, data) {
|
|
3617
|
+
console.log(err || data);
|
|
3618
|
+
}
|
|
3619
|
+
);
|
|
3620
|
+
}
|
|
3621
|
+
|
|
3622
|
+
// 图片样式 - 查询样式
|
|
3623
|
+
function describeImageStyles() {
|
|
3624
|
+
var host = config.Bucket + '.pic.' + config.Region + '.myqcloud.com/?style';
|
|
3625
|
+
var url = 'https://' + host;
|
|
3626
|
+
cos.request(
|
|
3627
|
+
{
|
|
3628
|
+
Method: 'GET',
|
|
3629
|
+
Url: url,
|
|
3630
|
+
Query: {
|
|
3631
|
+
// "style-name": 'style_name', // 非必填,样式名称
|
|
3632
|
+
},
|
|
3633
|
+
},
|
|
3634
|
+
function (err, data) {
|
|
3635
|
+
console.log(err || data);
|
|
3636
|
+
}
|
|
3637
|
+
);
|
|
3638
|
+
}
|
|
3639
|
+
|
|
3640
|
+
// 图片样式 - 删除样式
|
|
3641
|
+
function deleteImageStyle() {
|
|
3642
|
+
var host = config.Bucket + '.pic.' + config.Region + '.myqcloud.com/?style';
|
|
3643
|
+
var url = 'https://' + host;
|
|
3644
|
+
var body = COS.util.json2xml({
|
|
3645
|
+
DeleteStyle: {
|
|
3646
|
+
StyleName: 'style_name1', // 必须,样式名称
|
|
3647
|
+
},
|
|
3648
|
+
});
|
|
3649
|
+
cos.request(
|
|
3650
|
+
{
|
|
3651
|
+
Method: 'DELETE',
|
|
3652
|
+
Url: url,
|
|
3653
|
+
Body: body,
|
|
3654
|
+
ContentType: 'application/xml',
|
|
3655
|
+
},
|
|
3656
|
+
function (err, data) {
|
|
3657
|
+
console.log(err || data);
|
|
3658
|
+
}
|
|
3659
|
+
);
|
|
3660
|
+
}
|
|
3661
|
+
|
|
3662
|
+
// 开通 Guetzli 压缩
|
|
3663
|
+
function openImageGuetzli() {
|
|
3664
|
+
var host = config.Bucket + '.pic.' + config.Region + '.myqcloud.com/?guetzli';
|
|
3665
|
+
var url = 'https://' + host;
|
|
3666
|
+
cos.request(
|
|
3667
|
+
{
|
|
3668
|
+
Method: 'PUT',
|
|
3669
|
+
Url: url,
|
|
3670
|
+
},
|
|
3671
|
+
function (err, data) {
|
|
3672
|
+
console.log(err || data);
|
|
3673
|
+
}
|
|
3674
|
+
);
|
|
3675
|
+
}
|
|
3676
|
+
|
|
3677
|
+
// 查询 Guetzli 状态
|
|
3678
|
+
function describeImageGuetzli() {
|
|
3679
|
+
var host = config.Bucket + '.pic.' + config.Region + '.myqcloud.com/?guetzli';
|
|
3680
|
+
var url = 'https://' + host;
|
|
3681
|
+
cos.request(
|
|
3682
|
+
{
|
|
3683
|
+
Method: 'GET',
|
|
3684
|
+
Url: url,
|
|
3685
|
+
},
|
|
3686
|
+
function (err, data) {
|
|
3687
|
+
console.log(err || data);
|
|
3688
|
+
}
|
|
3689
|
+
);
|
|
3690
|
+
}
|
|
3691
|
+
|
|
3692
|
+
// 关闭 Guetzli 压缩
|
|
3693
|
+
function closeImageGuetzli() {
|
|
3694
|
+
var host = config.Bucket + '.pic.' + config.Region + '.myqcloud.com/?guetzli';
|
|
3695
|
+
var url = 'https://' + host;
|
|
3696
|
+
cos.request(
|
|
3697
|
+
{
|
|
3698
|
+
Method: 'DELETE',
|
|
3699
|
+
Url: url,
|
|
3700
|
+
},
|
|
3701
|
+
function (err, data) {
|
|
3702
|
+
console.log(err || data);
|
|
3703
|
+
}
|
|
3704
|
+
);
|
|
3705
|
+
}
|
|
3706
|
+
|
|
3707
|
+
// 上传时使用图片压缩
|
|
3708
|
+
function advanceCompressExample1() {
|
|
3709
|
+
var filename = 'example_photo.png';
|
|
3710
|
+
var filepath = path.resolve(__dirname, filename);
|
|
3711
|
+
cos.putObject(
|
|
3712
|
+
{
|
|
3713
|
+
Bucket: config.Bucket, // Bucket 格式:test-1250000000
|
|
3714
|
+
Region: config.Region,
|
|
3715
|
+
Key: filename,
|
|
3716
|
+
Body: fs.readFileSync(filepath),
|
|
3717
|
+
Headers: {
|
|
3718
|
+
// 通过 imageMogr2 接口进行 avif 压缩,可以根据需要压缩的类型填入不同的压缩格式:webp/heif/tpg/avif/svgc
|
|
3719
|
+
'Pic-Operations':
|
|
3720
|
+
'{"is_pic_info": 1, "rules": [{"fileid": "desample_photo.avif", "rule": "imageMogr2/format/webp"}]}',
|
|
3721
|
+
},
|
|
3722
|
+
onTaskReady: function (tid) {
|
|
3723
|
+
TaskId = tid;
|
|
3724
|
+
},
|
|
3725
|
+
onProgress: function (progressData) {
|
|
3726
|
+
console.log(JSON.stringify(progressData));
|
|
3727
|
+
},
|
|
3728
|
+
},
|
|
3729
|
+
function (err, data) {
|
|
3730
|
+
console.log(err || data);
|
|
3731
|
+
}
|
|
3732
|
+
);
|
|
3733
|
+
}
|
|
3734
|
+
|
|
3735
|
+
// 对云上数据进行图片压缩
|
|
3736
|
+
function advanceCompressExample2() {
|
|
3737
|
+
var filename = 'example_photo.png';
|
|
3738
|
+
cos.request(
|
|
3739
|
+
{
|
|
3740
|
+
Bucket: config.Bucket,
|
|
3741
|
+
Region: config.Region,
|
|
3742
|
+
Key: filename,
|
|
3743
|
+
Method: 'POST',
|
|
3744
|
+
Action: 'image_process',
|
|
3745
|
+
Headers: {
|
|
3746
|
+
// 通过 imageMogr2 接口进行 avif 压缩,可以根据需要压缩的类型填入不同的压缩格式:webp/heif/tpg/avif/svgc
|
|
3747
|
+
'Pic-Operations':
|
|
3748
|
+
'{"is_pic_info": 1, "rules": [{"fileid": "desample_photo.avif", "rule": "imageMogr2/format/avif"}]}',
|
|
3749
|
+
},
|
|
3750
|
+
},
|
|
3751
|
+
function (err, data) {
|
|
3752
|
+
console.log(err || data);
|
|
3753
|
+
}
|
|
3754
|
+
);
|
|
3755
|
+
}
|
|
3756
|
+
|
|
3757
|
+
// 下载时使用图片压缩
|
|
3758
|
+
function advanceCompressExample3() {
|
|
3759
|
+
var filepath = path.resolve(__dirname, 'example_photo_ci_result.avif');
|
|
3760
|
+
cos.getObject(
|
|
3761
|
+
{
|
|
3762
|
+
Bucket: config.Bucket,
|
|
3763
|
+
Region: config.Region,
|
|
3764
|
+
Key: 'example_photo.png',
|
|
3765
|
+
QueryString: `imageMogr2/format/avif`, // 可以根据需要压缩的类型填入不同的压缩格式:webp/heif/tpg/avif/svgc
|
|
3766
|
+
},
|
|
3767
|
+
function (err, data) {
|
|
3768
|
+
if (data) {
|
|
3769
|
+
fs.writeFileSync(filepath, data.Body);
|
|
3770
|
+
} else {
|
|
3771
|
+
console.log(err);
|
|
3772
|
+
}
|
|
3773
|
+
}
|
|
3774
|
+
);
|
|
3775
|
+
}
|
|
3776
|
+
|
|
3777
|
+
// 异常图片检测
|
|
3778
|
+
function createImageInspectJob() {
|
|
3779
|
+
var key = '1.png';
|
|
3780
|
+
var host = config.Bucket + '.cos.' + config.Region + '.myqcloud.com/' + key;
|
|
3781
|
+
var url = 'https://' + host;
|
|
3782
|
+
cos.request(
|
|
3783
|
+
{
|
|
3784
|
+
Method: 'GET',
|
|
3785
|
+
Key: key,
|
|
3786
|
+
Url: url,
|
|
3787
|
+
RawBody: true,
|
|
3788
|
+
Query: {
|
|
3789
|
+
'ci-process': 'ImageInspect' /* 必须,操作类型,异常图片检测固定为:ImageInspect */,
|
|
3790
|
+
},
|
|
3791
|
+
},
|
|
3792
|
+
function (err, data) {
|
|
3793
|
+
// 从响应数据中解析出异常图片检测结果
|
|
3794
|
+
let body = {};
|
|
3795
|
+
if (data && data.Body) {
|
|
3796
|
+
body = JSON.parse(data.Body) || {};
|
|
3797
|
+
if (body) {
|
|
3798
|
+
data.body = body;
|
|
3799
|
+
}
|
|
3800
|
+
}
|
|
3801
|
+
console.log(err || data);
|
|
3802
|
+
}
|
|
3803
|
+
);
|
|
3804
|
+
}
|
|
3805
|
+
|
|
3806
|
+
// 更新图片处理队列
|
|
3807
|
+
function updatePicProcessQueue() {
|
|
3808
|
+
// 任务所在的队列 ID,请使用查询队列(https://cloud.tencent.com/document/product/460/46946)获取或前往万象控制台(https://cloud.tencent.com/document/product/460/46487)在存储桶中查询
|
|
3809
|
+
var queueId = 'p36e92002ff5b418497076f31d33d4xxx';
|
|
3810
|
+
var host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com/picqueue/' + queueId;
|
|
3811
|
+
var url = 'https://' + host;
|
|
3812
|
+
var body = COS.util.json2xml({
|
|
3813
|
+
Request: {
|
|
3814
|
+
Name: 'My-Queue-Pic', // 必须,队列名称,长度不超过128
|
|
3815
|
+
State: 'Active', // 必须,Active 表示队列内的作业会被调度执行。Paused 表示队列暂停,作业不再会被调度执行,队列内的所有作业状态维持在暂停状态,已经执行中的任务不受影响。
|
|
3816
|
+
NotifyConfig: {
|
|
3817
|
+
// 必须,回调配置
|
|
3818
|
+
State: 'On', // 必须,回调开关,Off/On,默认Off
|
|
3819
|
+
Event: 'TaskFinish', // 回调事件,当 State=On时, 必选。任务完成:TaskFinish;工作流完成:WorkflowFinish
|
|
3820
|
+
ResultFormat: 'XML', // 非必选,回调格式,JSON/XML
|
|
3821
|
+
Type: 'Url', // 回调类型,当 State=On时, 必选,Url 或 TDMQ
|
|
3822
|
+
Url: 'https://www.example.com', // 回调地址,当 State=On, 且Type=Url时, 必选
|
|
3823
|
+
// MqMode: 'Off', // TDMQ 使用模式,当 State=On, 且Type=TDMQ时, 必选
|
|
3824
|
+
// MqRegion: 'Off', // TDMQ 所属地域,当 State=On, 且Type=TDMQ时, 必选
|
|
3825
|
+
// MqName: 'Off', // TDMQ 主题名称,当 State=On, 且Type=TDMQ时, 必选
|
|
3826
|
+
},
|
|
3827
|
+
},
|
|
3828
|
+
});
|
|
3829
|
+
cos.request(
|
|
3830
|
+
{
|
|
3831
|
+
Method: 'POST',
|
|
3832
|
+
Key: 'picqueue/' + queueId,
|
|
3833
|
+
Url: url,
|
|
3834
|
+
Body: body,
|
|
3835
|
+
ContentType: 'application/xml',
|
|
3836
|
+
},
|
|
3837
|
+
function (err, data) {
|
|
3838
|
+
console.log(err || data);
|
|
3839
|
+
}
|
|
3840
|
+
);
|
|
3841
|
+
}
|
|
3842
|
+
|
|
3843
|
+
// 查询图片处理队列
|
|
3844
|
+
function describePicProcessQueues() {
|
|
3845
|
+
var host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com/picqueue';
|
|
3846
|
+
var url = 'https://' + host;
|
|
3847
|
+
cos.request(
|
|
3848
|
+
{
|
|
3849
|
+
Method: 'GET',
|
|
3850
|
+
Key: 'picqueue',
|
|
3851
|
+
Url: url,
|
|
3852
|
+
Query: {
|
|
3853
|
+
// queueIds: '', /* 非必须,队列 ID,以“,”符号分割字符串 */
|
|
3854
|
+
state:
|
|
3855
|
+
'Active' /* 非必须,1. Active 表示队列内的作业会被媒体处理服务调度执行。2. Paused 表示队列暂停,作业不再会被媒体处理调度执行,队列内的所有作业状态维持在暂停状态,已经执行中的任务不受影响。 */,
|
|
3856
|
+
pageNumber: 1 /* 非必须,第几页,默认值1 */,
|
|
3857
|
+
pageSize: 10 /* 非必须,每页个数,默认值10 */,
|
|
3858
|
+
},
|
|
3859
|
+
},
|
|
3860
|
+
function (err, data) {
|
|
3861
|
+
console.log(err || data);
|
|
3862
|
+
}
|
|
3863
|
+
);
|
|
3864
|
+
}
|
|
3865
|
+
|
|
3866
|
+
// 查询已经开通文档预览的存储桶
|
|
3867
|
+
function describeDocProcessBuckets() {
|
|
3868
|
+
var host = 'ci.' + config.Region + '.myqcloud.com/docbucket';
|
|
3869
|
+
var url = 'https://' + host;
|
|
3870
|
+
cos.request(
|
|
3871
|
+
{
|
|
3872
|
+
Method: 'GET',
|
|
3873
|
+
Key: 'docbucket',
|
|
3874
|
+
Url: url,
|
|
3875
|
+
Query: {
|
|
3876
|
+
// regions: '', /* 非必须,地域信息,以“,”分隔字符串,支持 All、ap-shanghai、ap-beijing */
|
|
3877
|
+
// bucketNames: '', /* 非必须,存储桶名称,以“,”分隔,支持多个存储桶,精确搜索 */
|
|
3878
|
+
// bucketName: '', /* 非必须,存储桶名称前缀,前缀搜索 */
|
|
3879
|
+
// pageNumber: 1, /* 非必须,第几页 */
|
|
3880
|
+
// pageSize: 10, /* 非必须,每页个数 */
|
|
3881
|
+
},
|
|
3882
|
+
},
|
|
3883
|
+
function (err, data) {
|
|
3884
|
+
console.log(err || data);
|
|
3885
|
+
}
|
|
3886
|
+
);
|
|
3887
|
+
}
|
|
3888
|
+
|
|
3889
|
+
// 文档预览功能同步请求
|
|
3890
|
+
function previewDocumentAsync() {
|
|
3891
|
+
var key = 'test.docx';
|
|
3892
|
+
var host = config.Bucket + '.cos.' + config.Region + '.myqcloud.com/' + key;
|
|
3893
|
+
var url = 'https://' + host;
|
|
3894
|
+
cos.request(
|
|
3895
|
+
{
|
|
3896
|
+
Method: 'GET',
|
|
3897
|
+
Key: key,
|
|
3898
|
+
Url: url,
|
|
3899
|
+
Query: {
|
|
3900
|
+
ObjectKey: key /* 对象文件名 */,
|
|
3901
|
+
'ci-process': 'doc-preview' /* 必须,数据万象处理能力,文档预览固定为 doc-preview */,
|
|
3902
|
+
},
|
|
3903
|
+
},
|
|
3904
|
+
function (err, data) {
|
|
3905
|
+
console.log(err || data);
|
|
3906
|
+
}
|
|
3907
|
+
);
|
|
3908
|
+
}
|
|
3909
|
+
|
|
3910
|
+
// 提交文档转码任务
|
|
3911
|
+
function createDocProcessJobs() {
|
|
3912
|
+
var host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com/doc_jobs';
|
|
3913
|
+
var url = 'https://' + host;
|
|
3914
|
+
var body = COS.util.json2xml({
|
|
3915
|
+
Request: {
|
|
3916
|
+
Tag: 'DocProcess',
|
|
3917
|
+
Input: {
|
|
3918
|
+
Object: 'test.docx', // 存在cos里的路径
|
|
3919
|
+
},
|
|
3920
|
+
Operation: {
|
|
3921
|
+
DocProcess: {
|
|
3922
|
+
TgtType: 'jpg',
|
|
3923
|
+
},
|
|
3924
|
+
Output: {
|
|
3925
|
+
Bucket: config.Bucket,
|
|
3926
|
+
Region: config.Region,
|
|
3927
|
+
Object: '1/文档转码_${Number}.jpg', // 转码后存到cos的路径
|
|
3928
|
+
},
|
|
3929
|
+
},
|
|
3930
|
+
},
|
|
3931
|
+
});
|
|
3932
|
+
cos.request(
|
|
3933
|
+
{
|
|
3934
|
+
Method: 'POST',
|
|
3935
|
+
Key: 'doc_jobs',
|
|
3936
|
+
Url: url,
|
|
3937
|
+
Body: body,
|
|
3938
|
+
ContentType: 'application/xml',
|
|
3939
|
+
},
|
|
3940
|
+
function (err, data) {
|
|
3941
|
+
console.log(err || data);
|
|
3942
|
+
}
|
|
3943
|
+
);
|
|
3944
|
+
}
|
|
3945
|
+
|
|
3946
|
+
// 查询指定的文档预览任务
|
|
3947
|
+
function describeDocProcessJob() {
|
|
3948
|
+
var jobId = 'd622ab912ebdb11ed9baf0316d5139xxx'; // 替换成自己的jogId
|
|
3949
|
+
var host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com/doc_jobs/' + jobId;
|
|
3950
|
+
var url = 'https://' + host;
|
|
3951
|
+
cos.request(
|
|
3952
|
+
{
|
|
3953
|
+
Method: 'GET',
|
|
3954
|
+
Key: 'doc_jobs/' + jobId,
|
|
3955
|
+
Url: url,
|
|
3956
|
+
},
|
|
3957
|
+
function (err, data) {
|
|
3958
|
+
console.log(err || data);
|
|
3959
|
+
}
|
|
3960
|
+
);
|
|
3961
|
+
}
|
|
3962
|
+
|
|
3963
|
+
// 拉取符合条件的文档预览任务
|
|
3964
|
+
function describeDocProcessJobs() {
|
|
3965
|
+
var host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com/doc_jobs';
|
|
3966
|
+
var url = 'https://' + host;
|
|
3967
|
+
cos.request(
|
|
3968
|
+
{
|
|
3969
|
+
Method: 'GET',
|
|
3970
|
+
Key: 'doc_jobs',
|
|
3971
|
+
Url: url,
|
|
3972
|
+
Query: {
|
|
3973
|
+
tag: 'DocProcess',
|
|
3974
|
+
},
|
|
3975
|
+
},
|
|
3976
|
+
function (err, data) {
|
|
3977
|
+
console.log(err || data);
|
|
3978
|
+
}
|
|
3979
|
+
);
|
|
3980
|
+
}
|
|
3981
|
+
|
|
3982
|
+
// 更新文档预览队列
|
|
3983
|
+
function updateDocProcessQueue() {
|
|
3984
|
+
// 任务所在的队列 ID,请使用查询队列(https://cloud.tencent.com/document/product/460/46946)获取或前往万象控制台(https://cloud.tencent.com/document/product/460/46487)在存储桶中查询
|
|
3985
|
+
var queueId = 'p58639252a2cf45aba7a7f3335ffe3xxx'; // 替换成自己的队列id
|
|
3986
|
+
var host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com/docqueue/' + queueId;
|
|
3987
|
+
var url = 'https://' + host;
|
|
3988
|
+
var body = COS.util.json2xml({
|
|
3989
|
+
Request: {
|
|
3990
|
+
Name: 'queue-doc-process-1', // 替换成自己的队列name
|
|
3991
|
+
QueueID: queueId,
|
|
3992
|
+
State: 'Active',
|
|
3993
|
+
NotifyConfig: {
|
|
3994
|
+
State: 'Off',
|
|
3995
|
+
},
|
|
3996
|
+
},
|
|
3997
|
+
});
|
|
3998
|
+
cos.request(
|
|
3999
|
+
{
|
|
4000
|
+
Method: 'PUT',
|
|
4001
|
+
Key: 'docqueue/' + queueId,
|
|
4002
|
+
Url: url,
|
|
4003
|
+
Body: body,
|
|
4004
|
+
ContentType: 'application/xml',
|
|
4005
|
+
},
|
|
4006
|
+
function (err, data) {
|
|
4007
|
+
console.log(err || data);
|
|
4008
|
+
}
|
|
4009
|
+
);
|
|
4010
|
+
}
|
|
4011
|
+
|
|
4012
|
+
// 查询文档转码队列
|
|
4013
|
+
function describeDocProcessQueues() {
|
|
4014
|
+
var host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com/docqueue';
|
|
4015
|
+
var url = 'https://' + host;
|
|
4016
|
+
cos.request(
|
|
4017
|
+
{
|
|
4018
|
+
Method: 'GET',
|
|
4019
|
+
Key: 'docqueue',
|
|
4020
|
+
Url: url,
|
|
4021
|
+
Query: {
|
|
4022
|
+
// queueIds: '', /* 非必须,队列 ID,以“,”符号分割字符串 */
|
|
4023
|
+
// state: '', /* 非必须,1=Active,2=Paused */
|
|
4024
|
+
// pageNumber: 1, /* 非必须,第几页 */
|
|
4025
|
+
// pageSize: 2, /* 非必须,每页个数 */
|
|
4026
|
+
},
|
|
4027
|
+
},
|
|
4028
|
+
function (err, data) {
|
|
4029
|
+
console.log(err || data);
|
|
4030
|
+
}
|
|
4031
|
+
);
|
|
4032
|
+
}
|
|
4033
|
+
|
|
4034
|
+
// 文档转 HTML
|
|
4035
|
+
function getDocHtmlUrl() {
|
|
4036
|
+
cos.getObjectUrl(
|
|
4037
|
+
{
|
|
4038
|
+
Bucket: config.Bucket, // Bucket 格式:test-1250000000
|
|
4039
|
+
Region: config.Region,
|
|
4040
|
+
Key: 'test.docx',
|
|
4041
|
+
Query: {
|
|
4042
|
+
'ci-process': 'doc-preview' /* 必须,数据万象处理能力,文档预览固定为 doc-preview */,
|
|
4043
|
+
// srcType: '', /* 非必须,源数据的后缀类型,当前文档转换根据 COS 对象的后缀名来确定源数据类型。当 COS 对象没有后缀名时,可以设置该值 */
|
|
4044
|
+
// page: '', /* 非必须,需转换的文档页码,默认从1开始计数;表格文件中 page 表示转换的第 X 个 sheet 的第 X 张图 */
|
|
4045
|
+
dstType: 'html' /* 非必须,转换输出目标文件类型 */,
|
|
4046
|
+
},
|
|
4047
|
+
},
|
|
4048
|
+
function (err, data) {
|
|
4049
|
+
if (err) {
|
|
4050
|
+
console.log(err);
|
|
4051
|
+
} else {
|
|
4052
|
+
// 使用浏览器打开url即可预览
|
|
4053
|
+
var url = data.Url;
|
|
4054
|
+
console.log(url);
|
|
4055
|
+
}
|
|
4056
|
+
}
|
|
4057
|
+
);
|
|
4058
|
+
}
|
|
4059
|
+
|
|
4060
|
+
// 获取在线文档预览地址
|
|
4061
|
+
function getDocHtmlPreviewUrl() {
|
|
4062
|
+
var key = 'test.docx';
|
|
4063
|
+
var host = config.Bucket + '.cos.' + config.Region + '.myqcloud.com/' + key;
|
|
4064
|
+
var url = 'https://' + host;
|
|
4065
|
+
cos.request(
|
|
4066
|
+
{
|
|
4067
|
+
Method: 'GET',
|
|
4068
|
+
Key: key,
|
|
4069
|
+
Url: url,
|
|
4070
|
+
RawBody: true,
|
|
4071
|
+
Query: {
|
|
4072
|
+
'ci-process': 'doc-preview' /* 必须,预览固定参数,值为 doc-preview */,
|
|
4073
|
+
dstType: 'html' /* 必须,预览类型,如需预览生成类型为 html 则填入 html */,
|
|
4074
|
+
weboffice_url: 1 /* 非必须,是否获取预览链接。填入值为1会返回预览链接和Token信息;填入值为2只返回Token信息;不传会直接预览 */,
|
|
4075
|
+
},
|
|
4076
|
+
},
|
|
4077
|
+
function (err, data) {
|
|
4078
|
+
// 从响应数据中解析出在线文档预览地址
|
|
4079
|
+
let body = {};
|
|
4080
|
+
if (data && data.Body) {
|
|
4081
|
+
body = JSON.parse(data.Body) || {};
|
|
4082
|
+
}
|
|
4083
|
+
if (body && body.PreviewUrl) {
|
|
4084
|
+
data.PreviewUrl = body.PreviewUrl;
|
|
4085
|
+
}
|
|
4086
|
+
console.log(err || data);
|
|
4087
|
+
}
|
|
4088
|
+
);
|
|
4089
|
+
}
|
|
4090
|
+
|
|
4091
|
+
// 开通文件处理服务
|
|
4092
|
+
function createFileProcessBucket() {
|
|
4093
|
+
var host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com/file_bucket';
|
|
4094
|
+
var url = 'https://' + host;
|
|
4095
|
+
cos.request(
|
|
4096
|
+
{
|
|
4097
|
+
Method: 'POST',
|
|
4098
|
+
Key: 'file_bucket',
|
|
4099
|
+
Url: url,
|
|
4100
|
+
},
|
|
4101
|
+
function (err, data) {
|
|
4102
|
+
console.log(err || data);
|
|
4103
|
+
}
|
|
4104
|
+
);
|
|
4105
|
+
}
|
|
4106
|
+
|
|
4107
|
+
// 更新文件处理队列
|
|
4108
|
+
function updateFileProcessQueue() {
|
|
4109
|
+
// 任务所在的队列 ID,请使用查询队列(https://cloud.tencent.com/document/product/460/46946)获取或前往万象控制台(https://cloud.tencent.com/document/product/460/46487)在存储桶中查询
|
|
4110
|
+
var queueId = 'p5d0dc85debe149febdd6fd9b208aaxxx';
|
|
4111
|
+
var host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com/file_queue/' + queueId;
|
|
4112
|
+
var url = 'https://' + host;
|
|
4113
|
+
var body = COS.util.json2xml({
|
|
4114
|
+
Request: {
|
|
4115
|
+
Name: 'My-Queue-file', // 必须,队列名称,长度不超过128
|
|
4116
|
+
State: 'Active', // 必须,Active 表示队列内的作业会被调度执行。Paused 表示队列暂停,作业不再会被调度执行,队列内的所有作业状态维持在暂停状态,已经执行中的任务不受影响。
|
|
4117
|
+
NotifyConfig: {
|
|
4118
|
+
// 必须,回调配置
|
|
4119
|
+
State: 'On', // 必须,回调开关,Off/On,默认Off
|
|
4120
|
+
Event: 'TaskFinish', // 回调事件,当 State=On时, 必选。任务完成:TaskFinish;工作流完成:WorkflowFinish
|
|
4121
|
+
ResultFormat: 'XML', // 非必选,回调格式,JSON/XML
|
|
4122
|
+
Type: 'Url', // 回调类型,当 State=On时, 必选,Url 或 TDMQ
|
|
4123
|
+
Url: 'https://www.example.com', // 回调地址,当 State=On, 且Type=Url时, 必选
|
|
4124
|
+
// MqMode: 'Off', // TDMQ 使用模式,当 State=On, 且Type=TDMQ时, 必选
|
|
4125
|
+
// MqRegion: 'Off', // TDMQ 所属地域,当 State=On, 且Type=TDMQ时, 必选
|
|
4126
|
+
// MqName: 'Off', // TDMQ 主题名称,当 State=On, 且Type=TDMQ时, 必选
|
|
4127
|
+
},
|
|
4128
|
+
},
|
|
4129
|
+
});
|
|
4130
|
+
cos.request(
|
|
4131
|
+
{
|
|
4132
|
+
Method: 'POST',
|
|
4133
|
+
Key: 'file_queue/' + queueId,
|
|
4134
|
+
Url: url,
|
|
4135
|
+
Body: body,
|
|
4136
|
+
ContentType: 'application/xml',
|
|
4137
|
+
},
|
|
4138
|
+
function (err, data) {
|
|
4139
|
+
console.log(err || data);
|
|
4140
|
+
}
|
|
4141
|
+
);
|
|
4142
|
+
}
|
|
4143
|
+
|
|
4144
|
+
// 查询文件处理队列
|
|
4145
|
+
function describeFileProcessQueues() {
|
|
4146
|
+
var host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com/file_queue';
|
|
4147
|
+
var url = 'https://' + host;
|
|
4148
|
+
cos.request(
|
|
4149
|
+
{
|
|
4150
|
+
Method: 'GET',
|
|
4151
|
+
Key: 'file_queue',
|
|
4152
|
+
Url: url,
|
|
4153
|
+
Query: {
|
|
4154
|
+
// queueIds: '', /* 非必须,队列 ID,以“,”符号分割字符串 */
|
|
4155
|
+
state:
|
|
4156
|
+
'Active' /* 非必须,Active 表示队列内的作业会被调度执行。Paused 表示队列暂停,作业不再会被调度执行,队列内的所有作业状态维持在暂停状态,已经执行中的任务不受影响。 */,
|
|
4157
|
+
pageNumber: 1 /* 第几页,默认值1 */,
|
|
4158
|
+
pageSize: 10 /* 非必须,每页个数,默认值10 */,
|
|
4159
|
+
},
|
|
4160
|
+
},
|
|
4161
|
+
function (err, data) {
|
|
4162
|
+
console.log(err || data);
|
|
4163
|
+
}
|
|
4164
|
+
);
|
|
4165
|
+
}
|
|
4166
|
+
|
|
4167
|
+
// 哈希值计算同步请求
|
|
4168
|
+
function generateFileHash() {
|
|
4169
|
+
var key = 'test.docx';
|
|
4170
|
+
var host = config.Bucket + '.cos.' + config.Region + '.myqcloud.com/' + key;
|
|
4171
|
+
var url = 'https://' + host;
|
|
4172
|
+
cos.request(
|
|
4173
|
+
{
|
|
4174
|
+
Method: 'GET',
|
|
4175
|
+
Key: key,
|
|
4176
|
+
Url: url,
|
|
4177
|
+
Query: {
|
|
4178
|
+
'ci-process': 'filehash' /* 必须,操作类型,哈希值计算固定为:filehash */,
|
|
4179
|
+
type: 'md5' /* 必须,支持的哈希算法类型,有效值:md5、sha1、sha256 */,
|
|
4180
|
+
// 'addtoheader': false, /* 非必须,是否将计算得到的哈希值,自动添加至文件的自定义header,格式为:x-cos-meta-md5/sha1/sha256;有效值:true、false,不填则默认为false。 */
|
|
4181
|
+
},
|
|
4182
|
+
},
|
|
4183
|
+
function (err, data) {
|
|
4184
|
+
console.log(err || data);
|
|
4185
|
+
}
|
|
4186
|
+
);
|
|
4187
|
+
}
|
|
4188
|
+
|
|
4189
|
+
// 提交哈希值计算任务
|
|
4190
|
+
function postFileHashTask() {
|
|
4191
|
+
var host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com/file_jobs';
|
|
4192
|
+
var url = 'https://' + host;
|
|
4193
|
+
var body = COS.util.json2xml({
|
|
4194
|
+
Request: {
|
|
4195
|
+
Tag: 'FileHashCode', // 必须
|
|
4196
|
+
Input: {
|
|
4197
|
+
Object: 'test.docx', // 文件名,取值为文件在当前存储桶中的完整名称
|
|
4198
|
+
},
|
|
4199
|
+
Operation: {
|
|
4200
|
+
FileHashCodeConfig: {
|
|
4201
|
+
Type: 'MD5', // 哈希值的算法类型,有效值:MD5、SHA1、SHA256
|
|
4202
|
+
AddToHeader: 'false', // 是否将计算得到的哈希值添加至文件自定义header, 有效值:true、false,默认值为 false。
|
|
4203
|
+
},
|
|
4204
|
+
// UserData: '', // 透传用户信息, 可打印的 ASCII 码, 长度不超过1024
|
|
4205
|
+
},
|
|
4206
|
+
// QueueId: '', // 任务所在的队列 ID
|
|
4207
|
+
// CallBack: 'http://callback.demo.com', // 任务回调的地址
|
|
4208
|
+
// CallBackFormat: 'JSON', // 任务回调格式
|
|
4209
|
+
// CallBackType: 'Url', // 任务回调类型,Url 或 TDMQ,默认 Url
|
|
4210
|
+
},
|
|
4211
|
+
});
|
|
4212
|
+
cos.request(
|
|
4213
|
+
{
|
|
4214
|
+
Method: 'POST',
|
|
4215
|
+
Key: 'file_jobs',
|
|
4216
|
+
Url: url,
|
|
4217
|
+
Body: body,
|
|
4218
|
+
ContentType: 'application/xml',
|
|
4219
|
+
},
|
|
4220
|
+
function (err, data) {
|
|
4221
|
+
console.log(err || data);
|
|
4222
|
+
}
|
|
4223
|
+
);
|
|
4224
|
+
}
|
|
4225
|
+
|
|
4226
|
+
// 查询哈希值计算任务结果
|
|
4227
|
+
function getFileHashTask() {
|
|
4228
|
+
var jobId = 'f99ca3336ebde11ed96313ffa040a7xxx'; // 提交文件哈希值计算任务后会返回当前任务的jobId
|
|
4229
|
+
var host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com/file_jobs/' + jobId;
|
|
4230
|
+
var url = 'https://' + host;
|
|
4231
|
+
cos.request(
|
|
4232
|
+
{
|
|
4233
|
+
Method: 'GET',
|
|
4234
|
+
Key: 'file_jobs/' + jobId,
|
|
4235
|
+
Url: url,
|
|
4236
|
+
},
|
|
4237
|
+
function (err, data) {
|
|
4238
|
+
console.log(err || data);
|
|
4239
|
+
}
|
|
4240
|
+
);
|
|
4241
|
+
}
|
|
4242
|
+
|
|
4243
|
+
// 提交文件解压任务
|
|
4244
|
+
function postFileUnCompressTask() {
|
|
4245
|
+
var host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com/file_jobs';
|
|
4246
|
+
var url = 'https://' + host;
|
|
4247
|
+
var body = COS.util.json2xml({
|
|
4248
|
+
Request: {
|
|
4249
|
+
Tag: 'FileUncompress', // 必须
|
|
4250
|
+
Input: {
|
|
4251
|
+
Object: 'testCompress/compressed.zip', // 文件名,取值为文件在当前存储桶中的完整名称
|
|
4252
|
+
},
|
|
4253
|
+
Operation: {
|
|
4254
|
+
FileUncompressConfig: {
|
|
4255
|
+
Prefix: 'testCompress', // 指定解压后输出文件的前缀,不填则默认保存在存储桶根路径
|
|
4256
|
+
PrefixReplaced: '0', // 指定解压后的文件路径是否需要替换前缀,默认0
|
|
4257
|
+
},
|
|
4258
|
+
Output: {
|
|
4259
|
+
Bucket: config.Bucket, // 保存解压后文件的存储桶
|
|
4260
|
+
Region: config.Region, // 保存解压后文件的存储桶地域
|
|
4261
|
+
},
|
|
4262
|
+
},
|
|
4263
|
+
// QueueId: '', // 任务所在的队列 ID
|
|
4264
|
+
// CallBack: 'http://callback.demo.com', // 任务回调的地址
|
|
4265
|
+
// CallBackFormat: 'JSON', // 任务回调格式
|
|
4266
|
+
// CallBackType: 'Url', // 任务回调类型,Url 或 TDMQ,默认 Url
|
|
4267
|
+
},
|
|
4268
|
+
});
|
|
4269
|
+
cos.request(
|
|
4270
|
+
{
|
|
4271
|
+
Method: 'POST',
|
|
4272
|
+
Key: 'file_jobs',
|
|
4273
|
+
Url: url,
|
|
4274
|
+
Body: body,
|
|
4275
|
+
ContentType: 'application/xml',
|
|
4276
|
+
},
|
|
4277
|
+
function (err, data) {
|
|
4278
|
+
console.log(err || data);
|
|
4279
|
+
}
|
|
4280
|
+
);
|
|
4281
|
+
}
|
|
4282
|
+
|
|
4283
|
+
// 查询文件解压任务结果
|
|
4284
|
+
function getFileUnCompressTask() {
|
|
4285
|
+
var jobId = 'f52028b26ebe211edae4c1b36c787axxx'; // 提交文件解压任务后会返回当前任务的jobId
|
|
4286
|
+
var host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com/file_jobs/' + jobId;
|
|
4287
|
+
var url = 'https://' + host;
|
|
4288
|
+
cos.request(
|
|
4289
|
+
{
|
|
4290
|
+
Method: 'GET',
|
|
4291
|
+
Key: 'file_jobs/' + jobId,
|
|
4292
|
+
Url: url,
|
|
4293
|
+
},
|
|
4294
|
+
function (err, data) {
|
|
4295
|
+
console.log(err || data);
|
|
4296
|
+
}
|
|
4297
|
+
);
|
|
4298
|
+
}
|
|
4299
|
+
|
|
4300
|
+
// 提交文件压缩任务
|
|
4301
|
+
function postFileCompressTask() {
|
|
4302
|
+
var host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com/file_jobs';
|
|
4303
|
+
var url = 'https://' + host;
|
|
4304
|
+
var body = COS.util.json2xml({
|
|
4305
|
+
Request: {
|
|
4306
|
+
Tag: 'FileCompress', // 必须
|
|
4307
|
+
Operation: {
|
|
4308
|
+
FileCompressConfig: {
|
|
4309
|
+
Flatten: '0', // 文件打包时,是否需要去除源文件已有的目录结构.0:不需要;1:需要
|
|
4310
|
+
Format: 'zip', // 打包压缩的类型,有效值:zip、tar、tar.gz
|
|
4311
|
+
// UrlList、Prefix、Key 三者仅能选择一个,不能都为空,也不会同时生效
|
|
4312
|
+
// UrlList: '', // 索引文件的对象地址
|
|
4313
|
+
Prefix: '/', // 目录前缀
|
|
4314
|
+
Key: [''], // 支持对存储桶中的多个文件进行打包,个数不能超过 1000, 总大小不超过50G,否则会导致任务失败
|
|
4315
|
+
},
|
|
4316
|
+
Output: {
|
|
4317
|
+
Bucket: config.Bucket, // 保存压缩后文件的存储桶
|
|
4318
|
+
Region: config.Region, // 保存压缩后文件的存储桶地域
|
|
4319
|
+
Object: 'testCompress/compressed.zip', // 压缩后文件的文件名
|
|
4320
|
+
},
|
|
4321
|
+
UserData: '',
|
|
4322
|
+
},
|
|
4323
|
+
// QueueId: '', // 任务所在的队列 ID
|
|
4324
|
+
// CallBack: 'http://callback.demo.com', // 任务回调的地址
|
|
4325
|
+
// CallBackFormat: 'JSON', // 任务回调格式
|
|
4326
|
+
// CallBackType: 'Url', // 任务回调类型,Url 或 TDMQ,默认 Url
|
|
4327
|
+
},
|
|
4328
|
+
});
|
|
4329
|
+
cos.request(
|
|
4330
|
+
{
|
|
4331
|
+
Method: 'POST',
|
|
4332
|
+
Key: 'file_jobs',
|
|
4333
|
+
Url: url,
|
|
4334
|
+
Body: body,
|
|
4335
|
+
ContentType: 'application/xml',
|
|
4336
|
+
},
|
|
4337
|
+
function (err, data) {
|
|
4338
|
+
console.log(err || data);
|
|
4339
|
+
}
|
|
4340
|
+
);
|
|
4341
|
+
}
|
|
4342
|
+
|
|
4343
|
+
// 查询文件压缩任务结果
|
|
4344
|
+
function getFileCompressTask() {
|
|
4345
|
+
var jobId = 'fc3c90292ebdf11eda4be2be811d77xxx'; // 提交文件压缩任务后会返回当前任务的jobId
|
|
4346
|
+
var host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com/file_jobs/' + jobId;
|
|
4347
|
+
var url = 'https://' + host;
|
|
4348
|
+
cos.request(
|
|
4349
|
+
{
|
|
4350
|
+
Method: 'GET',
|
|
4351
|
+
Key: 'file_jobs/' + jobId,
|
|
4352
|
+
Url: url,
|
|
4353
|
+
},
|
|
4354
|
+
function (err, data) {
|
|
4355
|
+
console.log(err || data);
|
|
4356
|
+
}
|
|
4357
|
+
);
|
|
4358
|
+
}
|
|
4359
|
+
|
|
4360
|
+
// 存储桶操作
|
|
4361
|
+
// getService();
|
|
4362
|
+
// getAuth();
|
|
4363
|
+
// getV4Auth();
|
|
4364
|
+
// getObjectUrl();
|
|
4365
|
+
// putBucket();
|
|
4366
|
+
// getBucket();
|
|
4367
|
+
// headBucket();
|
|
4368
|
+
// putBucketAcl();
|
|
4369
|
+
// getBucketAcl();
|
|
4370
|
+
// putBucketCors();
|
|
4371
|
+
// getBucketCors();
|
|
4372
|
+
// deleteBucketCors();
|
|
4373
|
+
// putBucketTagging();
|
|
4374
|
+
// getBucketTagging();
|
|
4375
|
+
// deleteBucketTagging();
|
|
4376
|
+
// putBucketPolicy();
|
|
4377
|
+
// getBucketPolicy();
|
|
4378
|
+
// deleteBucketPolicy();
|
|
4379
|
+
// getBucketLocation();
|
|
4380
|
+
// getBucketLifecycle();
|
|
4381
|
+
// putBucketLifecycle();
|
|
4382
|
+
// deleteBucketLifecycle();
|
|
4383
|
+
// putBucketVersioning();
|
|
4384
|
+
// getBucketVersioning();
|
|
4385
|
+
// listObjectVersions();
|
|
4386
|
+
// getBucketReplication();
|
|
4387
|
+
// putBucketReplication();
|
|
4388
|
+
// deleteBucketReplication();
|
|
4389
|
+
// putBucketWebsite();
|
|
4390
|
+
// getBucketWebsite();
|
|
4391
|
+
// deleteBucketWebsite();
|
|
4392
|
+
// putBucketReferer();
|
|
4393
|
+
// getBucketReferer();
|
|
4394
|
+
// putBucketDomain();
|
|
4395
|
+
// getBucketDomain();
|
|
4396
|
+
// deleteBucketDomain();
|
|
4397
|
+
// putBucketOrigin();
|
|
4398
|
+
// getBucketOrigin();
|
|
4399
|
+
// deleteBucketOrigin();
|
|
4400
|
+
// putBucketLogging();
|
|
4401
|
+
// getBucketLogging();
|
|
4402
|
+
// deleteBucketLogging();
|
|
4403
|
+
// putBucketInventory();
|
|
4404
|
+
// getBucketInventory();
|
|
4405
|
+
// deleteBucketInventory();
|
|
4406
|
+
// listBucketInventory();
|
|
4407
|
+
// putBucketAccelerate();
|
|
4408
|
+
// getBucketAccelerate();
|
|
4409
|
+
// putBucketEncryption();
|
|
4410
|
+
// getBucketEncryption();
|
|
4411
|
+
// deleteBucketEncryption();
|
|
4412
|
+
// deleteBucket();
|
|
4413
|
+
|
|
4414
|
+
// 对象操作
|
|
4415
|
+
// putObjectCopy();
|
|
4416
|
+
// getObjectStream();
|
|
4417
|
+
// getObject();
|
|
4418
|
+
// headObject();
|
|
4419
|
+
// putObjectAcl();
|
|
4420
|
+
// getObjectAcl();
|
|
4421
|
+
// deleteObject();
|
|
4422
|
+
// deleteMultipleObject();
|
|
4423
|
+
// restoreObject();
|
|
4424
|
+
// abortUploadTask();
|
|
4425
|
+
// selectObjectContentStream();
|
|
4426
|
+
// selectObjectContent();
|
|
4427
|
+
// sliceUploadFile();
|
|
4428
|
+
// uploadFile();
|
|
4429
|
+
// uploadFiles();
|
|
4430
|
+
// cancelTask();
|
|
4431
|
+
// pauseTask();
|
|
4432
|
+
// restartTask();
|
|
4433
|
+
// putObject();
|
|
4434
|
+
// putObject_base64();
|
|
4435
|
+
// sliceCopyFile();
|
|
4436
|
+
// putObjectTagging();
|
|
4437
|
+
// getObjectTagging();
|
|
4438
|
+
// deleteObjectTagging();
|
|
4439
|
+
// appendObject();
|
|
4440
|
+
// appendObject_continue();
|
|
4441
|
+
|
|
4442
|
+
// 其他示例
|
|
4443
|
+
// moveObject();
|
|
4444
|
+
// uploadFolder();
|
|
4445
|
+
// createFolder();
|
|
4446
|
+
// listFolder();
|
|
4447
|
+
// deleteFolder();
|
|
4448
|
+
// downloadFile();
|
|
4449
|
+
// request();
|
|
4450
|
+
|
|
4451
|
+
// 数据处理
|
|
4452
|
+
// DescribeCIBuckets();
|
|
4453
|
+
// GetMediaInfo();
|
|
4454
|
+
// GetSnapshot();
|
|
4455
|
+
|
|
4456
|
+
//DescribeDocProcessBuckets();
|
|
4457
|
+
//GetDocProcess()
|
|
4458
|
+
//DescribeDocProcessQueues()
|
|
4459
|
+
//UpdateDocProcessQueue()
|
|
4460
|
+
//CreateDocProcessJobs();
|
|
4461
|
+
//DescribeDocProcessJob();
|
|
4462
|
+
//DescribeDocProcessJobs();
|
|
4463
|
+
//DescribeMediaBuckets();
|
|
4464
|
+
//DescribeMediaQueues();
|
|
4465
|
+
//UpdateMediaQueue();
|
|
4466
|
+
//CreateMediaTemplate();
|
|
4467
|
+
//DeleteMediaTemplate();
|
|
4468
|
+
//DescribeMediaTemplates()
|
|
4469
|
+
//UpdateMediaTemplate()
|
|
4470
|
+
//CreateMediaJobs();
|
|
4471
|
+
//CancelMediaJob();
|
|
4472
|
+
//DescribeMediaJob();
|
|
4473
|
+
//DescribeMediaJobs();
|
|
4474
|
+
|
|
4475
|
+
//CreateWorkflow();
|
|
4476
|
+
//DeleteWorkflow();
|
|
4477
|
+
//DescribeWorkflow();
|
|
4478
|
+
//DescribeWorkflowExecution();
|
|
4479
|
+
//DescribeWorkflowExecutions();
|
|
4480
|
+
//UpdateWorkflow();
|
|
4481
|
+
//TriggerWorkflow();
|
|
4482
|
+
//GetPrivateM3U8();
|
|
4483
|
+
|
|
4484
|
+
// SyncAuditImageObject()
|
|
4485
|
+
// SyncAuditImageUrl()
|
|
4486
|
+
// SyncAuditImageUrls()
|
|
4487
|
+
// SyncAuditTextContent()
|
|
4488
|
+
// CreateAuditJob()
|
|
4489
|
+
// DescribeAuditJob()
|
|
4490
|
+
// postLiveAuditing();
|
|
4491
|
+
// getLiveAuditingResult();
|
|
4492
|
+
|
|
4493
|
+
// postVirusDetect();
|
|
4494
|
+
// getVirusDetectResult();
|
|
4495
|
+
|
|
4496
|
+
// postNoiseReduction();
|
|
4497
|
+
// postVoiceSeparate();
|
|
4498
|
+
// postTts();
|
|
4499
|
+
// postSpeechRecognition();
|
|
4500
|
+
// getAsrQueue();
|
|
4501
|
+
// putAsrQueue();
|
|
4502
|
+
// getAsrBucket();
|
|
4503
|
+
|
|
4504
|
+
// setRefer();
|
|
4505
|
+
// describeRefer();
|
|
4506
|
+
// openOriginProtect();
|
|
4507
|
+
// describeOriginProtect();
|
|
4508
|
+
// closeOriginProtect();
|
|
4509
|
+
|
|
4510
|
+
// addImageStyle();
|
|
4511
|
+
// describeImageStyles();
|
|
4512
|
+
// deleteImageStyle();
|
|
4513
|
+
// openImageGuetzli();
|
|
4514
|
+
// describeImageGuetzli();
|
|
4515
|
+
// closeImageGuetzli();
|
|
4516
|
+
// advanceCompressExample1();
|
|
4517
|
+
// advanceCompressExample2();
|
|
4518
|
+
// advanceCompressExample3();
|
|
4519
|
+
// createImageInspectJob();
|
|
4520
|
+
// updatePicProcessQueue();
|
|
4521
|
+
// describePicProcessQueues();
|
|
4522
|
+
|
|
4523
|
+
// describeDocProcessBuckets();
|
|
4524
|
+
// previewDocumentAsync();
|
|
4525
|
+
// createDocProcessJobs();
|
|
4526
|
+
// describeDocProcessJob();
|
|
4527
|
+
// describeDocProcessJobs();
|
|
4528
|
+
// updateDocProcessQueue();
|
|
4529
|
+
// describeDocProcessQueues();
|
|
4530
|
+
// getDocHtmlUrl();
|
|
4531
|
+
// getDocHtmlPreviewUrl();
|
|
4532
|
+
|
|
4533
|
+
// createFileProcessBucket();
|
|
4534
|
+
// updateFileProcessQueue();
|
|
4535
|
+
// describeFileProcessQueues();
|
|
4536
|
+
// generateFileHash();
|
|
4537
|
+
// postFileHashTask();
|
|
4538
|
+
// getFileHashTask();
|
|
4539
|
+
// postFileUnCompressTask();
|
|
4540
|
+
// getFileUnCompressTask();
|
|
4541
|
+
// postFileCompressTask();
|
|
4542
|
+
// getFileCompressTask();
|