var remote = require('electron').remote;
var qiniu = require("qiniu");
qiniu.conf.ACCESS_KEY = 'Lis4yPv7zDXfQj_ZyDHsHRGgQPxm_3Oat5kw27ib';
qiniu.conf.SECRET_KEY = 'daYXkvWVMKbTOd7OyyjZ5duEq3Wz3Qq9pt-pw6K9';
var startUpload = function (filePath) {
filePath = "D:\\test1.txt";
//要上传的空间
var bucket = 'saas';
//上传到七牛后保存的文件名
var key = 'test1.txt';
//生成上传 Token
var token = uptoken(bucket, key);
uploadFile(token, key, filePath);
};
var uptoken = function (bucket, key) {
var putPolicy = new qiniu.rs.PutPolicy(bucket + ":" + key);
return putPolicy.token();
};
var uploadFile = function (uptoken, key, localFile) {
var extra = new qiniu.io.PutExtra();
qiniu.io.putFile(uptoken, key, localFile, extra, function (err, ret) {
if (!err) {
// 上传成功, 处理返回值
console.log(ret.hash, ret.key, ret.persistentId);
} else {
// 上传失败, 处理返回代码
console.log(err);
}
});
};
备注: var extra = new qiniu.io.PutExtra(); 这个地方报错
在node的Express环境下execPath的值 "D:\Program Files\nodejs\node.exe"
在electron环境下对应的值为:D:Workspace2017syn-assistantcodesyn-assistantnode_moduleselectrondistelectron.exe"
遇到了一样的问题,建议用这个apiqn