Image 微信上传拇指媒体文件问题
我目前正在使用微信管理平台api编写节点应用程序。然而,当我尝试使用管理平台api将thumb媒体图像文件上传到腾讯服务器时,我目前陷入了困境。我有一个在微信注册的用户账号,我能够使用admin api平台成功获取我的微信账号的访问令牌和关注者列表。 以下是我用来上传到微信服务器的微信代码:Image 微信上传拇指媒体文件问题,image,upload,media,wechat,Image,Upload,Media,Wechat,我目前正在使用微信管理平台api编写节点应用程序。然而,当我尝试使用管理平台api将thumb媒体图像文件上传到腾讯服务器时,我目前陷入了困境。我有一个在微信注册的用户账号,我能够使用admin api平台成功获取我的微信账号的访问令牌和关注者列表。 以下是我用来上传到微信服务器的微信代码: function uploadThumb(){ console.log('Inside uploadThumb'); var promise = new Promise(function(resolve
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;
}
在node中运行上述函数时,得到的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>
|
<a target="_blank" href="http://mp.weixin.qq.com/cgi-bin/readtemplate?t=wxm-agreement&type=info&lang=zh_CN">????</a>
|
<a target="_blank" href="http://kf.qq.com/special_auto/weixin.html">????</a>
</p>
<p class="copyright">
Copyright c 2012-2013 Tencent. All Rights Reserved.
</p>
</div>
</div>
</body>
</html>
状态:502
???
.dn{显示:无;}
.db{display:block;}
.dib{显示:内联块;}
.b_dib{显示:内联块;*显示:内联;*缩放:1;}
.di{display:inline;}
.vh{可见性:隐藏;}
.vv{可见性:可见;}
.rel{位置:相对;}
.abs{位置:绝对;}
.oh{溢出:隐藏;}
.z{*zoom:1;}
.l{float:左;}
.r{float:right;}
.cl{clear:两者;}
.group{*zoom:1;}
.group:在{content:“\200B”;显示:块;高度:0;清除:两者;}
.tc{文本对齐:居中;}
.tr{text align:right;}
.tl{文本对齐:左;}
.tj{text align:justify;*text justify:distribute;}
.vt{垂直对齐:顶部;}
.vm{垂直对齐:中间;}
.vb{垂直对齐:底部;}
.f0{字体大小:0;}
.fa{font-family:Arial;}
.fs{font-family:SimSun;}
.fyh{字体系列:“Microsoft YaHei”}
.indent{text indent:2em;}
.n{字体大小:400;字体样式:普通;}
.b{字体大小:700;}
.i{字体样式:斜体;}
.tdn{文本装饰:无;}
.tdn:hover{text装饰:无;}
.poi{cursor:pointer;}
.text隐藏{行高:999em;溢出:隐藏;}
.drop_hl_extra{左边填充:999em;左边空白:-999em;}
.drop_vb_extra{填充底部:999em;空白底部:-999em;}
html{-webkit文本大小调整:无;}
主体,h1,h2,h3,h4,h5,p,ul,ol,dl,dd{边缘:0;}
ul,ol{左填充:0;列表样式类型:无;}
img{border:0;}
正文{背景色:#EAEAEA;字体系列:“Microsoft YaHei”、Helvetica、Verdana、Arial、Tahoma;字体大小:14px;颜色:#22222;}
.logo{padding top:25px;}
.wrapper{width:960px;左边距:自动;右边距:自动;}
.container{margin top:20px;长方体阴影:0 3px 3px#ddd;-moz长方体阴影:0 3px 3px#ddd;-webkit长方体阴影:0 3px 3px#ddd;边框半径:3px;-moz边框半径
.err_包装{溢出:隐藏;*缩放:1;填充:100px 260px 100px 260px;}
.err_图标\u持有者{float:left;}
.erru内容{左边距:180px;顶端距:30px;}
.err_t{字体大小:700;字体大小:20px;行高:30px;}
.err_text{行高:28px;}
.footer{填充顶部:40px;字体大小:12px;颜色:#999999;文本阴影:0 1px 1px#ffffff;文本对齐:中心;}
.page_链接a{color:#4d5d2c;文本装饰:无;}
.err_图标{显示:内联块;宽度:170px;高度:130px;背景:透明url(“http://res.wx.qq.com/mpres/htmledition/images/icon_page_err.png)n
503:HTTP错误503
|
|
版权c 2012-2013腾讯。保留所有权利。
请帮我指出正确的方向,无论这种方法是正确的还是我做了一些基本错误的事情。根据我在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")
}
[...]
根据我在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")
}
[...]