关于数据库备份上传七牛云失败问题

来源:9-6 上传数据库备份到七牛私有云

James_dai

2017-09-03

我这边也遇到了问题,

我的文件名叫task

http://szimg.mukewang.com/59abc76e000164a705340532.jpg


1、在movie.backup.sh 文件中:

NODE_ENV=$backUpFolder@$backFileName node /home/leek_manager/task/upload.js

2、执行:sh movie.backup.sh

3、tar包文件已经生成:movie_2017_09_03_1654.tar.gz

4、但是后面执行报错如下:

/home/leek_manager/task/node_modules/qiniu/qiniu/storage/rs.js:659

    throw new Error('invalid putpolicy options');

    ^

Error: invalid putpolicy options

    at new PutPolicy (/home/leek_manager/task/node_modules/qiniu/qiniu/storage/rs.js:659:11)

    at uptoken (/home/leek_manager/task/upload.js:15:19)

    at Object.<anonymous> (/home/leek_manager/task/upload.js:19:9)

    at Module._compile (module.js:570:32)

    at Object.Module._extensions..js (module.js:579:10)

    at Module.load (module.js:487:32)

    at tryModuleLoad (module.js:446:12)

    at Function.Module._load (module.js:438:3)

    at Module.runMain (module.js:604:10)

    at run (bootstrap_node.js:394:7)


写回答

4回答

ochai

2017-09-20

我也遇到这个错误,请问一下你解决了吗?

2
2
ochai
排了下版: var qiniu = require('qiniu'); var parts = process.env.NODE_ENV.split('@'); var file = parts[1] + '.tar.gz'; //要上传文件的本地路径 var localFile = parts[0] + '/' + file; //需要填写你的 Access Key 和 Secret KEY var bucket = "imoocdeploydb"; var accessKey = '*****'; var secretKey = '******'; var mac = new qiniu.auth.digest.Mac(accessKey, secretKey); var options = { scope: bucket } var putPolicy = new qiniu.rs.PutPolicy(options); var uploadToken = putPolicy.uploadToken(mac); var config = new qiniu.conf.Config(); var formUploader = new qiniu.form_up.FormUploader(config); var putExtra = new qiniu.form_up.PutExtra(); //上传到七牛后保存的文件名 var key = file; // 文件上传 formUploader.putFile(uploadToken, null, 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); } });
2017-09-20
共2条回复

ehuo0123

2017-11-01

var qiniu = require("qiniu");


var accessKey = '你的accesskey';

var secretKey = '你的secrestkey';

var mac = new qiniu.auth.digest.Mac(accessKey, secretKey);


var bucket = '存储空间的名称';

var options = {

  scope: bucket,

};

var putPolicy = new qiniu.rs.PutPolicy(options);

var uploadToken=putPolicy.uploadToken(mac);



var config = new qiniu.conf.Config();

//不同的区域,取值不同,华东为z0

config.zone = qiniu.zone.Zone_z0;


var parts = process.env.NODE_ENV.split('@');

var key =  parts[1] + '.tar.gz';

var localFile =  parts[0] + '/' + key;


var formUploader = new qiniu.form_up.FormUploader(config);

var putExtra = new qiniu.form_up.PutExtra();

formUploader.putFile(uploadToken, key, 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);

  }

});


1
0

二位取根

2018-10-06

//img.mukewang.com/szimg/5bb887a30001978c06830853.jpg

如图所示,亲测成功

0
0

Scott

2017-09-04

七牛抽风了,到七牛的官方文档,参照他们最新的 SDK 用法来试下吧,七牛 SDK 升级,貌似不向下兼容

0
0

Node.js项目线上服务器部署与发布

阿里云部署Node.js+MongoDB+Nginx的应用项目,打通全栈

1747 学习 · 448 问题

查看课程