1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const COS = require('../../lib/cos-wx-sdk-v5');

const Key = '<filename>.jpg';

const config = {
SecretId: 'AKID<xxx>',
SecretKey: '<xxxx>',
urlPrefix: 'https://<BucketName>-<APPID>.pic.<Region>.myqcloud.com/' // e.g. img-1255000000.pic.ap-chengdu.myqcloud.com
};

const authorization = COS.getAuthorization({
SecretId: config.SecretId,
SecretKey: config.SecretKey,
Method: 'post',
Pathname: '/' + Key,
Expires: 60,
});

wx.request({
method: 'post',
url: config.urlPrefix + Key + '?image_process',
header: {
'Authorization': authorization,
'Pic-Operations': JSON.stringify({ "is_pic_info": 1, "rules": [{ "fileid": Key.replace('.', '.240x180.'), "rule": "imageView2/1/w/240/h/180/q/85" }] })
},
complete(res) {
console.log(res)
}
})