setImage:function(e){ var _this = this //坑1 wx.chooseImage({ count: 1, sizeType: ['original', 'compressed'], sourceType: ['album', 'camera'], success: function (res) { var tempFilePaths = res.tempFilePaths console.log(tempFilePaths) wx.uploadFile({ url: app.globalData.myhost+'customer-header?access_token='+app.globalData.itoken, filePath: tempFilePaths[0], name: 'uploadFile', formData: { 'userId': app.globalData.iuserId }, success: function (res) {var data = JSON.parse(res.data) //坑2:与wx.request不同,wx.uploadFile返回的是[字符串],需要自己转为JSON格式 console.log('上传成功') _this.setData({ //坑1:wx.uploadFile本身有一个this,所以要通过外部var _this = this 把this带进来 headerImageUrl: data.headerImageUrl }) console.log('刷新成功') } }) } }) },
微信小程序wx.uploadFile的两个坑
原创
©著作权归作者所有:来自51CTO博客作者mb61285b506f930的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
一直可以正常 git push 代码,突然就不行了,提示端口22错误,访问超时!
github网站正常访问,但是git push代码报错,提示端口22错误,访问超时!怎么搞?
git 端口错误 无法push git ssh -
微信小程序wx.uploadfile 本地文件转base64
微信小程序wx.uploadfile, 利用接口把本地图片转化为base64流.网上到处都是粘贴
base64流 php 图片转为base64流 wx.uploadfile 小程序