- 做了一个云函数,触发器是每当cos有图片上传的时候会调用这个函数。
- 这个函数用来使用数据万象中的持久化对上传的图片生成缩略图,再存储到cos的bucket中
- 万象数据, 云上持久化参考的文档链接是
https://cloud.tencent.com/document/product/460/18147
- COS 触发器的事件消息结构,参考的是这个文档
https://cloud.tencent.com/document/product/583/31927
问题: 代码中的http request 好像没有被执行过,因为没有在console中打印任何东西,也同时没有报任何错误,不知道如何排错,大家请指教。
代码片段如下:
const path = require('path')
const request = require('request')
const COS = require('cos-nodejs-sdk-v5')
const config = {
SecretId: 'my-id',
SecretKey: 'my-key',
Host: 'xxxx-88888888.cos.na-toronto.myqcloud.com',
Bucket: 'xxxx-88888888',
Region: 'na-toronto',
}
var cos = new COS({
// 必选参数
SecretId: config.SecretId,
SecretKey: config.SecretKey,
});
exports.main_handler = async (event, context, callback) => {
let thumbImgName = '/thumb_propertyImages'
let { Records } = event
// 获取cos签名
var auth = cos.getAuth({
Method: 'get',
Key: Records[0].cos.cosObject.key,
// Key: url,
Expires: 60,
});
// 设置http请求参数
var options = {
url: 'https://'+config.Host+Records[0].cos.cosObject.key+'?image_process',
headers: {
'Pic-Operations': JSON.stringify({"is_pic_info":1,"rules":[{"fileid":thumbImgName,"rule":"imageView2/1/w/750/h/560"}]}),
'Authorization': auth,
//'Content-Length': Records[0].cos.cosObject.size
},
};
// http 请求开始
request.post(options,(err, response, body)=>{
console.log("err",err);
console.log("response",response);
console.log("body",body);
return 'test';
})
}