node上传文件到七牛云

第一步:上传凭证
                

  var _accessKey = '';
  var _secretKey = '';
  var mac = new qiniu.auth.digest.Mac(_accessKey, _secretKey);
  var options = {
    scope: '上传空间名字',
  };
  var putPolicy = new qiniu.rs.PutPolicy(options);
  var uploadToken=putPolicy.uploadToken(mac);

第二步:构建配置config 上传对应的空间地区
             
  var config = new qiniu.conf.Config();
  config.zone = qiniu.zone.Zone_z1; //华北
第三步:上传
       1--简单文件
            
  var localFile = "/Users/Desktop/img/chi.png";
  var formUploader = new qiniu.form_up.FormUploader(config);
  var putExtra = new qiniu.form_up.PutExtra();
  var key='test.png';
  // 文件上传
  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);
    }
  });


你可能感兴趣的:(node,七牛,上传)