小程序图片上传

 uploadimg:function(){
    var that = this;
    wx.chooseImage({ //从本地相册选择图片或使用相机拍照
     count: 1, // 默认9
     sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
     sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
     success:function(res){
     //console.log(res)
     //前台显示
     that.setData({
      source: res.tempFilePaths
     })
     // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
     var tempFilePaths = res.tempFilePaths
      wx.uploadFile({
      url: 'http://qicun.rdmate.com/qicun/wc_mini_program.common/uploadFile',//接口地址
      filePath: tempFilePaths[0],//图片路径
      name: 'images',//请求参数
       
      success:function(res){
      //打印
      console.log(res.data)
      }
     })
      
     }
    })
    },
正道的光终将来临,当太阳升起的时候,光芒总会普照大地温暖人间。些许的阴霾也终会有被阳光洒满的一天
原文地址:https://www.cnblogs.com/sjruxe/p/14692746.html