var qiniu = require("qiniu");
bucket = '1v1';
var accessKey = 'qKJM7ruEYGhN6q3eoEUD3Ep6RfaPr-esV6Bxdzer';
var secretKey = 'iiBt1mGKOP5A8yYoaiWJ0MbKCoZVaUuAxsn-8KDf';
var date = new Date();;
var upload_file = date.getFullYear() + '-' + date.getMonth() + '-' + date.getDate() + '/' +date.getHours() + '-' + date.getMinutes() + '-' + date.getSeconds() + '.mp4';
var pipeline = '1v1queue';
fops = "avthumb/mp4/s/640x360/vb/1.25m"
saveas_key = qiniu.util.urlsafeBase64Encode(bucket+':'+upload_file);
fops = fops+'|saveas/'+saveas_key;;
var mac = new qiniu.auth.digest.Mac(accessKey, secretKey);
var options = {
scope: bucket,
}
var putPolicy = new qiniu.rs.PutPolicy(options);
putPolicy.persistentOps = fops;
putPolicy.persistentPipeline = pipeline;
var uploadToken = putPolicy.uploadToken(mac);
var config = new qiniu.conf.Config();
config.useCdnDomain = true;
var localFile = './test.mp4';
var formUploader = new qiniu.form_up.FormUploader(config);
var putExtra = new qiniu.form_up.PutExtra();
formUploader.putFile(uploadToken, upload_file, localFile, putExtra, function(respErr, respBody, respInfo) {
if (respErr) {
throw respErr;
}
if (respInfo.statusCode == 200) {
console.log(respBody);
} else {
console.log(respInfo.statusCode);
console.log(respBody);
}
});