Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// 引入七牛 Node.js SDK
var qiniu = require('qiniu');
var fs = require('fs');
// 设置全局参数,包括必须的 AccessKey 和 SecretKey,
// 还可以设置其他如 CallbackURL 等参数,将会顺延至所有空间。
qiniu.config({
access_key: '------',
secret_key: '------'
});
// 获得空间对象
var imagesBucket = qiniu.bucket('qiniu-sdk-test');
// 也可以这样操作
// var imagesBucket = new qiniu.Bucket('qiniu-sdk-test');
// 上传一个文件,参数为将要上传的 Key,文件地址(可以是绝对地址,也可以是相对地址),
// 第三个为可选参数 options,即本次上传中所使用 PutToken 的特殊设置,
// 第四个为可选参数回调(callback),
// 若不传入回调函数,将由 putFile 函数所返回的 Promise 对象进行响应。
imagesBucket.putFile('exampleKey', __dirname + '/assets/example.jpg', function(err, reply) {
if (err) {
return console.error(err);
}
console.dir(reply);
});
imagesBucket.putFile('exampleKey_1', __dirname + '/assets/example.jpg', {
// 为本次上传中所使用的 Token 进行设置,此处为设置上传者标识