收藏
回答

camera组件 我在拍照函数中加了一个上传图片到服务起的函数 然后真机调试可以 线上不可以 点解?

camera组件

微信版本号8.0.1

takePhoto() {

    var that = this;

    const ctx = wx.createCameraContext()

    console.log(ctx);

    ctx.takePhoto({

      quality: 'high',

      success: (res) => {     

        console.log(this.data.src)

        this.setData({

          src: res.tempImagePath

        })

     

        that.goac();

        

      },

      error(e){

        console.log(e.detail);

        wx.showToast({

          title: ''+e.detail,

          icon:'none'

        })

      }

    })

  },

  goac:function(){

    var that = this;

    console.log('启动啦');

    wx.uploadFile({

      url:garbage+'user/doFaceImage', //此处换上你的接口地址

      filePath: this.data.src,

      name: 'image',

      header: {

        "Content-Type": "multipart/form-data",

        'accept': 'application/json',

        // "language":wx.getStorageSync('ulg')

      },

      formData: {

        // ulanguage:app.globalData.ulanguage,

        userToken:wx.getStorageSync('userToken'),

        userid:wx.getStorageSync('userId')

      },

      success: function (res) {

       console.log(res);

      var ccc = that.data.src

        // console.log(res.data.status=="200")

        if(res.statusCode==200){

          wx.showToast({

            title: '录入成功',

            icon: 'success',

            duration: 1500

          })

          that.setData({

            srcc: ccc

          })

         

          // wx.showToast({

          //   title: '实名认证成功',

          //   icon: 'success',

          //   duration: 2000

          // })

        }

      },

      fail: function (res) {

        console.log(res)

        console.log('fail');

      },

    })

  },

  error(e) {

    console.log(e.detail)

  }

})

代码如下

回答关注问题邀请回答
收藏
登录 后发表内容
问题标签