qiniu.js
713 Bytes
/**
* 七牛上传
* @author: chenfeng <feng.chen@yoho.cn>
* @date: 29/06/2017
*/
const qiniu = require('qiniu');
const qiniuConfig = global.yoho.config.qiniu;
const qiniuYohoCdnConfig = global.yoho.config.qiniuYohoCdn;
function getToken(req, res) {
let conf = qiniuConfig;
if (req.query.type === 'yohoCdn') {
conf = qiniuYohoCdnConfig;
}
let mac = new qiniu.auth.digest.Mac(conf.ACCESS_KEY, conf.SECRET_KEY);
let options = {
scope: conf.BUCKET_NAME
};
let putPolicy = new qiniu.rs.PutPolicy(options);
let uploadToken = putPolicy.uploadToken(mac);
res.json({
code: 200,
uptoken: uploadToken
});
}
module.exports = {
getToken
};