1 Star 0 Fork 0

z1y3/study_client

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
upload_source.js 1.01 KB
一键复制 编辑 原始数据 按行查看 历史
z1y3 提交于 2020-04-15 20:43 . initialize project
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);
}
});
})();
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/z1y3/study_client.git
git@gitee.com:z1y3/study_client.git
z1y3
study_client
study_client
master

搜索帮助