1

我目前正在使用微信管理平台api编写节点应用程序。但是,当我尝试使用管理平台 api 将拇指媒体图像文件上传到腾讯服务器时,我目前被卡住了。我有一个在微信上注册的订阅者帐户,我可以使用管理 api 平台成功获取我的微信帐户的访问令牌和关注者列表。以下是我用来上传到微信服务器的微信代码:

function uploadThumb(){

console.log('Inside uploadThumb');

var promise = new Promise(function(resolve,reject){

    resolve({
        then:function(onfullfill,onreject){
             fs.readdir(thumb_dir,function(err,files){
             if (err){
                onreject();
                throw err;
            }
            files.forEach(function(file){
                 fs.stat(thumb_dir+file, function(err, stats) {
                       var type = "thumb";
                       var upload_url = "http://file.api.wechat.com/cgi-bin/media/upload?access_token="+access_token+"&type="+type;
                     console.log('file name :'+file+': size :'+stats.size);
            restler.post(upload_url, {
                          multipart: true,
                          data: {
                                   "media['filename']": file,
                                   "media['content type']":"image/png",
                                   "media['file length']": stats.size,
                                   "media['file']": restler.file(thumb_dir+file, null, stats.size, null, "image/png")
                                }
                        }).on("complete", function(fdata,response) {
                              console.log('Status: ' + response.statusCode);
                              console.log('Thumb image data :'+fdata);
                              console.dir(response);
                             //var obj = JSON.parse(fdata);
                         //saveUploadMediaToDB(obj,file).then(onfullfill());
                            onfullfill();
                             });
                          });
                      });
                  });               
               }
          });
      });
      return promise;
   }

当我在节点中运行上述函数时,我得到的 HTTP 响应代码为 502。下面的文本/html 响应:

    Status: 502
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="UTF-8">
  <title>???</title>
  <style type="text/css">
  .dn{display:none;}
  .db{display:block;}
  .dib{display:inline-block;}
  .b_dib{display:inline-block;*display:inline;*zoom:1;}
  .di{display:inline;}
  .vh{visibility:hidden;}
  .vv{visibility:visible;}
  .rel{position:relative;}
  .abs{position:absolute;}
  .oh{overflow:hidden;}
  .z{*zoom:1;}
  .l{float:left;}
  .r{float:right;}
  .cl{clear:both;}
  .group{*zoom:1;}
  .group:after{content:"\200B";display:block;height:0;clear:both;}
  .tc{text-align:center;}
  .tr{text-align:right;}
  .tl{text-align:left;}
  .tj{text-align:justify;*text-justify:distribute;}
  .vt{vertical-align:top;}
  .vm{vertical-align:middle;}
  .vb{vertical-align:bottom;}
  .f0{font-size:0;}
  .fa{font-family:Arial;}
  .fs{font-family:SimSun;}
  .fyh{font-family:"Microsoft YaHei";}
  .indent{text-indent:2em;}
  .n{font-weight:400;font-style:normal;}
  .b{font-weight:700;}
  .i{font-style:italic;}
  .tdn{text-decoration:none;}
  .tdn:hover{text-decoration:none;}
  .poi{cursor:pointer;}
  .text-hide{line-height:999em;overflow:hidden;}
  .drop_hl_extra{padding-left:999em;margin-left:-999em;}
  .drop_vb_extra{padding-bottom:999em;margin-bottom:-999em;}
  html{-webkit-text-size-adjust:none;}
  body,h1,h2,h3,h4,h5,p,ul,ol,dl,dd{margin:0;}
  ul,ol{padding-left:0;list-style-type:none;}
  a img{border:0;}
  body{background-color:#EAEAEA;font-family:"Microsoft YaHei",Helvetica,Verdana,Arial,Tahoma;font-size:14px;color:#222222;}
  .logo{padding-top:25px;}
  .wrapper{width:960px;margin-left:auto;margin-right:auto;}
  .container{margin-top:20px;box-shadow:0 3px 3px #ddd;-moz-box-shadow:0 3px 3px #ddd;-webkit-box-shadow:0 3px 3px #ddd;border-radius:3px;-moz-border-rad
  .err_wrapper{overflow:hidden;*zoom:1;padding:100px 260px 100px 260px;}
  .err_icon_holder{float:left;}
  .err_content{margin-left:180px;margin-top:30px;}
  .err_t{font-weight:700;font-size:20px;line-height:30px;}
  .err_text{line-height:28px;}
  .footer{padding-top:40px;font-size:12px;color:#999999;text-shadow:0 1px 1px #ffffff;text-align:center;}
  .page_link a{color:#4d5d2c;text-decoration:none;}
  .err_icon{display:inline-block;width:170px;height:130px;background:transparent url("http://res.wx.qq.com/mpres/htmledition/images/icon_page_err.png") n

  </style>
</head>
<body>
  <div class="header">
    <div class="wrapper">
      <h1 class="logo"><a href="http://mp.weixin.qq.com"><img src="http://res.wx.qq.com/mpres/htmledition/images/login/logo.png" alt="??????"></a></h1>
    </div>

  </div>
  <div class="main">
    <div class="wrapper">
      <div class="container">
        <div class="err_wrapper">
          <span class="err_icon_holder"><i class="err_icon page_503"></i></span>
          <div class="err_content">
            <h3 class="err_t">503 : HTTP Error 503</h3>
            <p class="err_text">???????,????????</p>
          </div>
        </div>
      </div>

    </div>

  </div>
  <div class="footer">
    <div class="wrapper">
      <p class="page_link">
        <a target="_blank" href="http://www.tencent.com/zh-cn/index.shtml">????</a>
        &nbsp;|&nbsp;
        <a target="_blank" href="http://mp.weixin.qq.com/cgi-bin/readtemplate?t=wxm-agreement&amp;type=info&amp;lang=zh_CN">????</a>
        &nbsp;|&nbsp;
        <a target="_blank" href="http://kf.qq.com/special_auto/weixin.html">????</a>
      </p>
      <p class="copyright">
        Copyright&nbsp;c 2012-2013 Tencent. All Rights Reserved.
      </p>
    </div>

  </div>


</body>
</html>

请指出正确的方向来帮助我,无论这种方法是正确的还是我做的事情基本上是错误的。

4

1 回答 1

0

根据我在 Restler 文档中找到的内容,并将其与微信 API 文档进行比较,您似乎指定了错误的请求参数。

我想你可能需要更换

restler.post(upload_url, {
  multipart: true,
  data: {
    "media['filename']": file,
    "media['content type']":"image/png",
    "media['file length']": stats.size,
    "media['file']": restler.file(thumb_dir+file, null, stats.size, null, "image/png")
  }
[...]

沿着这些思路:

restler.post(upload_url, {
  multipart: true,
  data: {
    "media": restler.file(thumb_dir+file, null, stats.size, null, "image/png")
  }
[...]
于 2016-01-22T07:02:09.483 回答