码迷,mamicode.com
首页 > 微信 > 详细

微信小程序wx.uploadFile的两个坑

时间:2020-01-16 01:01:37      阅读:99      评论:0      收藏:0      [点我收藏+]

标签:host   一个   parse   type   url   刷新   有一个   ade   his   

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的两个坑

标签:host   一个   parse   type   url   刷新   有一个   ade   his   

原文地址:https://www.cnblogs.com/xubao/p/12199367.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!