WeChat applet docking with Tencent Object Storage

Anyone who has read the document knows that I don’t understand it very well (I’m a novice) Fortunately, there is a demo

 cos get signature 

we need two files 


One is the cos-wx-sdk-v5.js provided by Tencent, please download it from Baidu or git (you can search it)

Another is the configuration information we save, please write it in another js, such as  config.js

var config = {
Bucket: '' , //replace with yours
Region: 'ap-chengdu' , //replace with yours
SecretId: '' , //replace with yours
SecretKey: '' //replace with yours
}

module .exports = config

Add the following where you need to add business

var COS = require ( '../../lib/cos-wx-sdk-v5' )
var config = require ( '../../lib/config' )
var files = []
var filescount = 0
var id= 0;
var cos = new COS({ //实例化cos类
getAuthorization: function (params, callback) { //获取签名 必填参数
var authorization = COS.getAuthorization({
SecretId: config.SecretId,
SecretKey: config.SecretKey,
Method: params.Method,
Key: params.Key
});
callback(authorization);
}
});

下面就是执行文件对象上传操作的方法

cos.postObject({
Bucket: config.Bucket,
Region: config.Region,
Key: yskey,
FilePath: filePath
}, function (err, data) {
JiaruFile(yskeyCl[ 2 ] + '.' + yskeyCl[ 3 ]) //Join the database to join the database business and delete and add as needed
filescount = filescount + 1
zhixing()//This is a concurrent event for me to upload multiple pictures
});
over









Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325521928&siteId=291194637