如下代码第二个then返回undefined,但是用开发者调试工具上传临时素材却可以成功上传并获得mediaId,说明accesstoken应该没问题,相关代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 | .then( function (data){ var url = api.upload + '&access_token=' + data + '&type=' + type; console.log(url,form) request({ method: 'POST' , url:url, json: true , formData:form, }) }) .then( function (res){ console.log( '返回的:' ,res); }) |
在第一个then中打印出的url与调试工具中的url相同,说明url正确。问题可能出在form上,我将form打印出来如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | { media: ReadStream { _readableState: ReadableState { objectMode: false , highWaterMark: 65536, buffer: [Object], length: 65083, pipes: null , pipesCount: 0, flowing: null , ended: true , endEmitted: false , reading: false , sync: false , needReadable: false , emittedReadable: true , readableListening: false , resumeScheduled: false , defaultEncoding: 'utf8' , ranOut: false , awaitDrain: 0, readingMore: false , decoder: null , encoding: null }, readable: true , domain: null , _events: { end: [Function] }, _eventsCount: 1, _maxListeners: undefined, path: 'C:\\Users\\Administrator\\node\\task\\day05\\wechat\\金刚狼.jpg' , fd: 3, flags: 'r' , mode: 438, start: undefined, end: undefined, autoClose: true , pos: undefined } } |
请老师帮忙分析下