gpake / qiniu-wxapp-sdk

qiniu SDK based on wxapp
GNU General Public License v3.0
703 stars 278 forks source link

微信小程序无法上传图片 #5

Closed sysu-lian closed 7 years ago

sysu-lian commented 7 years ago

我想使用七牛云实现小程序的图片上传,我测试了你们提供的demo, 1 参数配置如下: { uploadURL: 'https://up-z2.qbox.me', region: 'SCN', // 现使用华南区 shouldUseQiniuFileName: false, domain: 'oqsxl5bup.bkt.clouddn.com', // 这是我的bucket key: 'customFileName.jpg', uptoken: token // 此时的token由后端服务器实时生成 } 2 调试报错如下: WAService.js:3 thirdScriptError Unexpected token u in JSON at position 0;at pages/index/index didPressChooesImage function;at api uploadFile success callback function SyntaxError: Unexpected token u in JSON at position 0 at success (http://1953992292.appservice.open.weixin.qq.com/utils/qiniuUploader.js:101:31) at Object.success (http://1953992292.appservice.open.weixin.qq.com/WAService.js:3:7222) at . (http://1953992292.appservice.open.weixin.qq.com/WAService.js:4:25475) at . (http://1953992292.appservice.open.weixin.qq.com/asdebug.js:1:15029) at http://1953992292.appservice.open.weixin.qq.com/WAService.js:3:7222

3 我仔细核对了你们的sdk使用说明,却并没有找到使用不当地方。在单步调试过程中,发现如下: 微信的 wx.chooseImage函数正确返回了图片的路径filePath wxfile://tmp_1953992292o6zAJs6PljyNcFSJ_PbqvlOfmQZEe98364026356c6875c482c2d282ec664.JPG 但是,执行到你们的函数:qiniuUploader.upload(filePath, (res)),却报错,详见2

4 若是需要我补充调试信息,请尽快告诉我。希望可以得到你们的帮助,谢谢。

gpake commented 7 years ago

It seems that JSON parse failed, I'v updated the error callback at 50f1963b0ba3f7304c5b8d04f33fdcf87c51ea0c, please update the SDK, and check what the error is, or print is directly at qiniuUploader.js:101:31 success callback, I haven't reproduce this error

sysu-lian commented 7 years ago

Thanks for your reply.

1 I have updated the SDK as you advise. But it seems that the problem hasn't been solved. The result as follows.

qiniuUploader.js [sm]:112 parse JSON failed, origin String is: undefined index.js [sm]:93 error: SyntaxError: Unexpected token u in JSON at position 0

2 I think there is something wrong with 'res.data' at qiniuUploader.js:99:5, so I add one code as 'console.log(res)' at qiniuUploader.js: 100:5 , just behind 'var dataString = res.data'. The result as follows.

Object {errMsg: "uploadFile:ok", statusCode: 401}

The error code is 401, Unauthorized ??

3 Looking forward to hear your reply.

gpake commented 7 years ago

抱歉刚用英文回复 401代表 token 出错,比如过期。你可以尝试重新生成一个 token 试试看。 如果依然报错,请检查 token 生成相关代码。 参见:https://segmentfault.com/q/1010000004731359https://segmentfault.com/q/1010000004001375 以及我应该再更新一下报错的内容,现在这个不利于判断错误。。

sysu-lian commented 7 years ago

已确认,是token的key配置参数问题,导致出错。问题已解决,谢谢。