数据万象Cloud Infinite(扩展)
Usage
const extCi = require('@cloudbase/extension-ci')
tcb.init({
env:'xxx',
});
tcb.registerExtension(extCi)
const res = await tcb.invokeExtension('CloudInfinite',opts)
opts包含以下属性
名称 | 类型 | 是否必须 | 说明 |
---|---|---|---|
action | string | 是 | 操作类型 |
cloudPath | string | 是 | 文件的绝对路径,与tcb.uploadFile中一致,除盲水印功能外,其它功能必须存在此路径的文件 |
fileContent | Uint8Array|Buffer|ArrayBuffer | 否 | 文件内容, 盲水印选传 |
operations | object | 否 | 数据万象的headers中的Pic-Operations字段,图像处理或者盲水印功能时需要填入的参数 |
action
目前包含以下类型
- DetectLabel
- DetectType
- WaterMark
- ImageProcess
fileContent在云函数和前端的获取方式参考
// 云函数中
const fileContent = fs.readFileSync('C:\\Users\\user\\Desktop\\bb.png'),
// 网页中
const readFile = async function(file) {
let reader = new FileReader();
let res = await new Promise(resolve=>{
reader.onload = function(e) {
let arrayBuffer = new Uint8Array((e.target as any).result);
resolve(arrayBuffer)
}
reader.readAsArrayBuffer(file);
})
return res
}
let file = document.getElementById('selectFile').files[0]
let fileContent = await readFile(file)
功能说明
图像处理
参考文档万象文档 云上数据处理
const ops = {
rules:[{
rule:'QRcode/cover/0'
}]
}
const res = await tcb.invokeExtension('CloudInfinite',{
cloudPath: "bb.png",
action:'ImageProcess',
operations:ops
})
console.log(JSON.stringify(res,null,4))
}
盲水印
参考文档万象文档 盲水印功能
const ops = {
rules:[{
fileid:'qr6.jpg'
rule:{
mode:3,
type:3,
text:'1234'
}
}]
}
const res = await tcb.invokeExtension('CloudInfinite',{
action:'WaterMark',
cloudPath: "qr5.jpg",
fileContent: fs.readFileSync('C:\\Users\\xxx\\Desktop\\bb.png'),
operations:ops
})
图片标签
参考文档万象文档 图片标签
const res = await tcb.invokeExtension('CloudInfinite',{
action:'DetectLabel',
cloudPath: "ab.png"
})
console.log(JSON.stringify(res,null,4))
安全审核
参考文档万象文档 内容识别
const opts = {
type: "porn" // 审核类型:porn(涉黄识别)、terrorist(涉暴恐识别)、politics(涉政识别)、ads(广告识别),可选择多种识别类型,如porn,ads
}
const res = await tcb.invokeExtension('CloudInfinite',{
action:'DetectType',
operations:opts,
cloudPath: "ab.png"
})
console.log(JSON.stringify(res,null,4))