How to use the qiniu.rs function in qiniu

To help you get started, we’ve selected a few qiniu examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github qiniu / js-sdk / test / server.js View on Github external
var mac = new qiniu.auth.digest.Mac(config.AccessKey, config.SecretKey);
var config2 = new qiniu.conf.Config();
// 这里主要是为了用 node sdk 的 form 直传,结合 demo 中 form 方式来实现无刷新上传
config2.zone = qiniu.zone.Zone_z2;
var formUploader = new qiniu.form_up.FormUploader(config2);
var putExtra = new qiniu.form_up.PutExtra();
var options = {
  scope: config.Bucket,
  deleteAfterDays: 1,
  returnBody:
    '{"key":"$(key)","hash":"$(etag)","fsize":$(fsize),"bucket":"$(bucket)","name":"$(x:name)"}'
};

var putPolicy = new qiniu.rs.PutPolicy(options);
var bucketManager = new qiniu.rs.BucketManager(mac, null);

app.get("/api/uptoken", function(req, res, next) {
  var token = putPolicy.uploadToken(mac);
  res.header("Cache-Control", "max-age=0, private, must-revalidate");
  res.header("Pragma", "no-cache");
  res.header("Expires", 0);
  if (token) {
    res.json({
      uptoken: token,
      domain: config.Domain
    });
  }
});

app.post("/api/transfer", function(req, res) {
  var form = new multiparty.Form();
github qiniu / nodejs-sdk / examples / rs_batch_change_type.js View on Github external
const qiniu = require('qiniu');
const proc = require('process');

var accessKey = proc.env.QINIU_ACCESS_KEY;
var secretKey = proc.env.QINIU_SECRET_KEY;
var mac = new qiniu.auth.digest.Mac(accessKey, secretKey);
var config = new qiniu.conf.Config();
var bucketManager = new qiniu.rs.BucketManager(mac, config);

var srcBucket = proc.env.QINIU_TEST_BUCKET;

// 每个operations的数量不可以超过1000个,如果总数量超过1000,需要分批发送
var changeTypeOperations = [
    qiniu.rs.changeTypeOp(srcBucket, 'qiniu1.mp4', 1),
    qiniu.rs.changeTypeOp(srcBucket, 'qiniu2.mp4', 1),
    qiniu.rs.changeTypeOp(srcBucket, 'qiniu3.mp4', 1),
    qiniu.rs.changeTypeOp(srcBucket, 'qiniu4.mp4', 1)
];

bucketManager.batch(changeTypeOperations, function (err, respBody, respInfo) {
    if (err) {
        console.log(err);
    // throw err;
    } else {
github qiniu / nodejs-sdk / examples / rs_batch_delete_after_days.js View on Github external
const qiniu = require('qiniu');
const proc = require('process');

var accessKey = proc.env.QINIU_ACCESS_KEY;
var secretKey = proc.env.QINIU_SECRET_KEY;
var mac = new qiniu.auth.digest.Mac(accessKey, secretKey);
var config = new qiniu.conf.Config();
var bucketManager = new qiniu.rs.BucketManager(mac, config);

var srcBucket = proc.env.QINIU_TEST_BUCKET;

// 每个operations的数量不可以超过1000个,如果总数量超过1000,需要分批发送
var deleteAfterDaysOperations = [
    qiniu.rs.deleteAfterDaysOp(srcBucket, 'qiniu1.mp4', 10),
    qiniu.rs.deleteAfterDaysOp(srcBucket, 'qiniu2.mp4', 10),
    qiniu.rs.deleteAfterDaysOp(srcBucket, 'qiniu3.mp4', 10),
    qiniu.rs.deleteAfterDaysOp(srcBucket, 'qiniu4.mp4', 10)
];

bucketManager.batch(deleteAfterDaysOperations, function (err, respBody, respInfo) {
    if (err) {
        console.log(err);
    // throw err;
    } else {
github bugulink / bugu-web / src / middlewares / cdn.js View on Github external
export function uploadIndex(files) {
  const bucManager = new qiniu.rs.BucketManager(mac, conf);
  // validity 1 hour
  const deadline = parseInt(Date.now() / 1000) + 3600;
  const urls = files.map((v, i) => {
    const url = bucManager.privateDownloadUrl(domain, encodePath(v.key), deadline);
    return `/url/${encode64(url)}/alias/${encode64((i + 1) + '-' + v.name)}`;
  });
  const options = {
    scope: bucket
  };
  const putPolicy = new qiniu.rs.PutPolicy(options);
  const uploadToken = putPolicy.uploadToken(mac);
  const formUploader = new qiniu.form_up.FormUploader(conf);
  const putExtra = new qiniu.form_up.PutExtra();

  return new Promise((resolve, reject) => {
    formUploader.put(uploadToken, null, urls.join('\r\n'), putExtra, (err,
      res) => {
      err ? reject(err) : resolve(res);
    });
  });
}
github zhen-ke / electron-qiniu / src / renderer / components / Bucket.vue View on Github external
getUploadToken(val) {
      // 获取上传Token
      var options = {
        scope: val,
        expires: new Date().getTime() + 3600, // 一个小时后过期
        saveKey: `$(fname)`, // 默认使用文件名作为图片的名称
        returnBody:
          '{"fname":"$(fname)","key":"$(key)","hash":"$(etag)","fsize":$(fsize),"bucket":"$(bucket)","name":"$(x:name)"}'
      };
      var putPolicy = new qiniu.rs.PutPolicy(options);
      return putPolicy.uploadToken(this.mac);
    },
    // getAccessToken(val) {
github yunlzhang / lcddjmwebsite / server / routes / files / gettoken.js View on Github external
let express = require('express');
let router = express.Router();
let qiniu  = require('qiniu');
let config = require('../../config');
let accessKey = config.qiniu.accessKey;
let secretKey = config.qiniu.secretKey;

let options = {
    scope: 'pict',
};
let putPolicy = new qiniu.rs.PutPolicy(options);

router.get('/',function(req,res,next){
    let mac = new qiniu.auth.digest.Mac(accessKey, secretKey);
    let uploadToken=putPolicy.uploadToken(mac);
    res.json({
        code:200,
        uptoken:uploadToken
    })
})
module.exports = router;
github KevinOfNeu / rocket / lib / provider / Qiniu.js View on Github external
function generateUploadtoken(bucket, cloudFileName) {
  var putPolicy = new qiniu.rs.PutPolicy(bucket + ":" + cloudFileName);
  return putPolicy.token();
}
github zhuowenli / zhuowenli.github.io / views / admin / build / qiniu.js View on Github external
function uptoken(buckets, key) {
        const putPolicy = new qiniu.rs.PutPolicy(`${buckets}:${key}`);
        return putPolicy.token();
    }
github lscho / ThinkJS-Vue.js-blog / src / service / upload.js View on Github external
let QN = require("qiniu");
        const config = await think.model('config').cache('config').getList();
        if (think.isEmpty(config)) {
            return false;
        }
        const qiniu = config.qiniu;
        if (think.isEmpty(qiniu)) {
            return false;
        }

        const bucket = qiniu.bucket;
        const accessKey = qiniu.access_key;
        const secretKey = qiniu.secret_key;

        const mac = new QN.auth.digest.Mac(accessKey, secretKey);
        const putPolicy = new QN.rs.PutPolicy({ scope: bucket });
        const uploadToken = putPolicy.uploadToken(mac);
        const qnConfig = new QN.conf.Config();
        const formUploader = new QN.form_up.FormUploader(qnConfig);
        const putExtra = new QN.form_up.PutExtra();

        const localFile = data.filepath;

        return new Promise((resolve, reject) => {
            formUploader.putFile(uploadToken, data.basename, localFile, putExtra, (respErr, respBody, respInfo) => {
                if (respErr) {
                    reject(respErr);
                }
                if (respInfo.statusCode == 200) {
                    resolve(respBody);
                } else {
                    reject(respBody);