qiniu.js
718 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
* 七牛上传
* @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;
let type = req.query.type || '';
if (type.toLowerCase() === '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
};