wechat проблема с загрузкой медиафайла большого пальца

В настоящее время я пишу приложение узла, используя API платформы администрирования wechat. Однако в настоящее время я застрял, когда пытаюсь загрузить файл изображения большого пальца на сервер tencent, используя API платформы администратора. У меня есть учетная запись подписчика, зарегистрированная в wechat, и я могу успешно получить токен доступа и список подписчиков моей учетной записи wechat, используя платформу admin api. Ниже приведен код wechat, который я использую для загрузки на сервер wechat:

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. И ответ text/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>

Пожалуйста, помогите мне, указав правильное направление, правильный ли этот подход или я делаю что-то в основном неправильное.


person Manoj Pathak    schedule 08.01.2016    source источник


Ответы (1)


Основываясь на том, что мне удалось найти в документации Restler, и сравнив ее с документацией API WeChat, кажется, что вы можете указать неверный параметр запроса.

Я думаю, вам может понадобиться заменить

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")
  }
[...]
person garbetjie    schedule 22.01.2016