代码拉取完成,页面将自动刷新
const qiniu = require('qiniu'), //npm i qiniu -S
{ keys, bucket, files } = require('./configs/qiniu');
qiniu.conf.ACCESS_KEY = keys.ak;
qiniu.conf.SECRET_KEY = keys.sk;
;(() => {
function uploadtoken(bucket, key) {
var policy = new qiniu.rs.PutPolicy({ isPrefixalScope: 1, scope: bucket + ':' + key });
return policy.uploadToken();
}
const config = new qiniu.conf.Config(),
putExtra = new qiniu.form_up.PutExtra(),
formUploader = new qiniu.form_up.FormUploader(config);
files.map(async (file) => {
const upToken = uploadtoken(bucket.name, file.name);
try {
formUploader.putFile(upToken, file.name, file.path, putExtra, (err, data) => {
if (err) {
console.log('Failed to upload data.(101)');
console.log(err);
return;
}
console.log('Data has been uploaded successfully.');
console.log(data);
})
} catch (err) {
console.log('Failed to upload data.(102)');
console.log(err);
}
});
})();
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。