请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

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

我这边也遇到了问题,

我的文件名叫task

https://img1.sycdn.imooc.com/szimg//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)


正在回答 回答被采纳积分+3

4回答

ochai 2017-09-20 21:06:38

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

2 回复 有任何疑惑可以回复我~
  • ochai #1
    新彼参考了一个官方github,可以上传了。给大家分享一下:
    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, 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);
      }
    });
    回复 有任何疑惑可以回复我~ 2017-09-20 21:42:51
  • ochai #2
    排了下版:
     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 21:46:57
ehuo0123 2017-11-01 02:39:38

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 回复 有任何疑惑可以回复我~
二位取根 2018-10-06 18:00:35

https://img1.sycdn.imooc.com//szimg/5bb887a30001978c06830853.jpg

如图所示,亲测成功

0 回复 有任何疑惑可以回复我~
Scott 2017-09-04 21:29:45

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

0 回复 有任何疑惑可以回复我~
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信