errcode: 41005,mediaId: undefined,上传临时图片素材时提示的错误
来源:4-4 第四天 上传临时素材之图片和视频
星辰Iron
2016-10-30
content发送1-4之间的消息能够正常回复,一发5、6就不行,看后台的情况是无法获取到data
代码如下:
else if (content === '5'){ var data = yield wechatApi.uploadMaterial('image',path.join(__dirname,'/2.jpg')) reply = { type: 'image', mediaId: data.media_id } console.log(data) console.log(reply) }
Wechat.prototype.uploadMaterial = function(type, filepath){ var that = this var form = {//构造一个表单 media: fs.createReadStream(filepath) } var appID = this.appID var appSecret = this.appSecret // var url = api.accessToken + '&appid=' + appID + '&secret=' + appSecret return new Promise(function(resolve,reject){//Promise 实例 that .fetchAccessToken() .then(function(data){ var url = api.upload + 'access_token=' + data. access_token + '&type=' + type request({methos: 'POST',url: url, formData:form, json: true}).then(function(response){ var _data = response[1] if(_data){ resolve(_data) console.log(_data) } else{ throw new Error('Upload material fails') } }) .catch(function(err){ reject(err) }) }) }) }
3回答
-
Scott
2016-10-30
用 response.body 代替 response[1] 试试看呢
012016-10-31 -
星辰Iron
提问者
2016-10-31
找到问题所在了,原来是我那个method拼错了。
012017-06-12 -
星辰Iron
提问者
2016-10-31
用 response.body 代替 response[1]之后报错如下:
Error: Upload material fails
at E:\Users\wechat-master\wechat\wechat.js:127:31
at tryCatcher (E:\Users\wechat-master\node_modules\bluebird\js\main\util.j
s:26:23)
at Promise._settlePromiseFromHandler (E:\Users\wechat-master\node_modules\
bluebird\js\main\promise.js:507:31)
at Promise._settlePromiseAt (E:\Users\wechat-master\node_modules\bluebird\
js\main\promise.js:581:18)
at Promise._settlePromises (E:\Users\wechat-master\node_modules\bluebird\j
s\main\promise.js:697:14)
at Async._drainQueue (E:\Users\wechat-master\node_modules\bluebird\js\main
\async.js:123:16)
at Async._drainQueues (E:\Users\wechat-master\node_modules\bluebird\js\mai
n\async.js:133:10)
at Immediate.Async.drainQueues [as _onImmediate] (E:\Users\wechat-master\n
ode_modules\bluebird\js\main\async.js:15:14)
00
相似问题