• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

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

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

--

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('刷新成功')
          }
        })
      }
    })
  },

 

 

 

--


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
    热门话题
    阅读排行榜

    扫描微信二维码

    查看手机版网站

    随时了解更新最新资讯

    139-2527-9053

    在线客服(服务时间 9:00~18:00)

    在线QQ客服
    地址:深圳市南山区西丽大学城创智工业园
    电邮:jeky_zhao#qq.com
    移动电话:139-2527-9053

    Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap