小程序图片上传

时间:2021-04-23 16:15:49   收藏:0   阅读:17
 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

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!