tencentyun-ci
v2.0.5
Published
node sdk for qcloud 万象优图2.0
Downloads
3
Readme
tencentyun/image-nodejs-sdk
腾讯云 万象优图(Cloud Image) SDK for Node.js
安装
npm install tencentyun-ci --save
动态指定您的配置
tencentyun.conf.setAppInfo('111', 'secretid', 'secretkey');
运行测试程序
修改sample/samplev2.js
文件中的配置参数,否则提示错误信息智能鉴黄imageprocess.pornDetect { code: 11, message: 'secretid not exist', data: {} }
npm install && npm start
V2版本空间和自定义文件名的上传,查询和删除示例
var tencentyun = require('../');
// 自定义空间名称,在http://console.qcloud.com/ci/bucket创建
var bucket = 'bucket';
// 前三个参数在https://console.qcloud.com/ci/secret查看,bucket在https://console.qcloud.com/ci/bucket 查看
tencentyun.conf.setAppInfo('111', 'secretid', 'secretkey', bucket);
//智能鉴黄
var pornUrl = 'http://b.hiphotos.baidu.com/image/pic/item/8ad4b31c8701a18b1efd50a89a2f07082938fec7.jpg';
tencentyun.imageprocess.pornDetect(pornUrl, function(ret){
console.log(ret);
});
//智能鉴黄-Url
var pornUrl = [
'http://b.hiphotos.baidu.com/image/pic/item/8ad4b31c8701a18b1efd50a89a2f07082938fec7.jpg',
'http://c.hiphotos.baidu.com/image/h%3D200/sign=7b991b465eee3d6d3dc680cb73176d41/96dda144ad3459829813ed730bf431adcaef84b1.jpg',
];
tencentyun.imageprocess.pornDetectUrl(pornUrl, function(ret){
console.log(ret);
});
//智能鉴黄-File
var pornFile = [
'D:/porn/test1.jpg',
'D:/porn/test2.jpg',
'../../../../../porn/test3.png',
];
tencentyun.imageprocess.pornDetectFile(pornFile, function(ret){
console.log(ret);
});
// 自定义文件名
var fileid = 'sample' + parseInt(Date.now() / 1000);
tencentyun.imagev2.upload('/tmp/amazon.jpg', bucket, fileid, function(ret){
console.log(ret);
if (0 == ret.code) {
var fileid = ret.data.fileid;
// 查询
tencentyun.imagev2.stat(bucket, fileid, function(ret) {
console.log(ret);
});
var fileid = ret.data.fileid;
// 生成私密下载url
var expired = parseInt(Date.now() / 1000) + 60;
var sign = tencentyun.auth.getAppSignV2(bucket, fileid, expired);
console.log('downloadUrl is : ' + ret.data.downloadUrl + '?sign=' + sign);
// 复制
tencentyun.imagev2.copy(bucket, fileid, function(ret) {
console.log(ret);
});
// 生成新的上传签名
var expired = parseInt(Date.now() / 1000) + 60;
var sign = tencentyun.auth.getAppSignV2(bucket, fileid, expired);
console.log('sign is :'+sign);
/*
tencentyun.imagev2.delete(bucket, fileid, function(ret) {
console.log(ret);
});
*/
}
});
图片和微视频上传、查询、删除程序示例
var tencentyun = require('../');
tencentyun.conf.setAppInfo('200679', 'AKIDoleG4e6U0j6EVQcjWXxzSO2Vv7Hqlgp2', 'ROlw3XYdNXNnII18ATs6zd7m5mivnApa');
tencentyun.image.upload('/tmp/amazon.jpg', function(ret){
var fileid = ret.data.fileid;
// 查询
tencentyun.image.stat(fileid, function(ret) {
console.log(ret);
});
var fileid = ret.data.fileid;
// 复制
tencentyun.image.copy(fileid, function(ret) {
console.log(ret);
// 生成私密下载url
var sign = tencentyun.auth.appSign(ret.data.downloadUrl, 0);
console.log(ret.data.downloadUrl + '?sign=' + sign);
});
// 生成新的上传签名,60秒后过期(如果发现签名无效,请尝试校准时钟或者加入QQ群324357952联系我们)
var expired = parseInt(Date.now() / 1000) + 60;
var sign = tencentyun.auth.appSign('http://web.image.myqcloud.com/photos/v1/200679/0/', expired);
console.log(sign);
tencentyun.image.delete(fileid, function(ret) {
console.log(ret);
});
});
// 带自定义信息的上传
tencentyun.video.upload('/tmp/085523020515bc3137630770.mp4', function(ret){
var fileid = ret.data.fileid;
tencentyun.video.stat(fileid, function(ret) {
console.log(ret);
});
var fileid = ret.data.fileid;
tencentyun.video.delete(fileid, function(ret) {
console.log(ret);
});
}, 'myvideos', {'title':'测试', 'desc':'这是一个测试'}, 'testimage');