E企盈营销工具技术服务商 热线:4006-838-530

微信小程序上传图片音频视频

E企盈直播平台营销卖货系统

wxml:button  bindtap=’imageUpload’上传图片/buttonbutton  bindtouchstart=”startRecode” bindtouchend=”endRecode” class=”cxbtn”上传音频/buttonbutton  bindtap=’videoUpload’上传视频/buttonjs:imageUpload(){    var that = this;//选择图片    wx.chooseImage({      count: 1,      sizeType: [‘original’, ‘compressed’],      sourceType: [‘album’, ‘camera’],      success(res) {        // tempFilePath可以作为img标签的src属性显示图片        const tempFilePaths = res.tempFilePaths        that.upImgs(tempFilePaths[0],0);      }    })  },//上传图片  upImgs: function (imgurl, index) {    var that = this;    wx.uploadFile({      url: api.image_upload,//      filePath: imgurl,      name: ‘file’,      header: {        ‘content-type’: ‘multipart/form-data’      },      formData: null,      success: function (res) {        var data = JSON.parse(res.data);        var data2 = JSON.parse(data.data);        that.setData({          picPath: data2.path        })        wx.showToast({          title: ‘图片上传成功’,          icon: ‘success’,          duration: 2000        })      }    })  },   //选择音频  startRecode: function () {    var that = this;    console.log(“start”);    wx.startRecord({      success: function (res) {        console.log(res);        var tempFilePath = res.tempFilePath;        that.setData({          recodePath: tempFilePath,           isRecode: true         });      },      fail: function (res) {        console.log(“fail”);        console.log(res);        //录音失败      }    });  },  endRecode: function () { //结束录音     var that = this;    console.log(“end”);    wx.stopRecord();    that.setData({       isRecode: false    });    // wx.showToast();    setTimeout(function () {      console.log(that.data.recodePath);      wx.uploadFile({        url: api.audio_upload,//上传接口        filePath: that.data.recodePath,        name: ‘file’,        header: {          ‘content-type’: ‘multipart/form-data’        },        success: function (res) {          var str = res.data;          var data = JSON.parse(str);          if (data.states == 1) {            var cEditData = s.data.editData;            cEditData.recodeIdentity = data.identitys;            that.setData({ editData: cEditData });          }          else {            wx.showModal({              title: ‘提示’,              content: ‘上传成功’,              showCancel: false,              success: function (res) {              }            });          }          wx.hideToast();        },        fail: function (res) {          console.log(res);          wx.showModal({            title: ‘提示’,            content: “网络请求失败,请确保网络是否正常”,            showCancel: false,            success: function (res) {            }          });          wx.hideToast();        }      });    }, 1000)  },//选择视频videoUpload : function () {    var that = this    wx.chooseVideo({      sourceType: [‘album’, ‘camera’],      maxDuration: 60,      camera: ‘back’,      success: function (res) {        that.setData({          video: res.tempFilePath,          size: (res.size / (1024 * 1024)).toFixed(2)        })        // 调用上传接口      }    })  },

赞(0) 打赏
未经允许不得转载:E企盈小程序开发-热线:4006-838-530 » 微信小程序上传图片音频视频
分享到: 更多 (0)
E企盈小程序直播营销卖货系统
E企盈直播平台营销卖货系统

评论 抢沙发

E企盈小程序开发

联系我们联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏