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

微信小程序wx.uploadFile上传视频遇到的两个坑

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

var _this = this;      wx.chooseVideo({          sourceType: [‘album’, ‘camera’],          maxDuration: 60,          camera: ‘back’,          success(res) {                       const uploadTask = wx.uploadFile({                  url: ”, // 上传到服务器                  filePath: res.tempFilePath,                  name: ‘file’,                  header: {                      “Content-Type”: “multipart/form-data”                  },                  formData: {                      fileKey: fileKey                  },                  success(res) {                      const data = JSON.parse(res.data);// 坑一:与wx.request不同,wx.uploadFile返回的是json字符串,需要自己转为JSON对象格式                      console.log(data);                      }              });              uploadTask.onProgressUpdate((res) => {                  const uploadProgress = res.progress;                  if(uploadProgress < 100){                     // 坑2:wx.uploadFile本身有一个this,所以要通过外部var _this = this 把this带进来                      _this.setData({                          uploadPercent: uploadProgress                      });                  } else if(uploadProgress === 100){                      _this.setData({                          uploadPercent: 50                      });                  }                  console.log(‘上传进度’, res.progress);                  console.log(‘已经上传的数据长度’, res.totalBytesSent);                  console.log(‘预期需要上传的数据总长度’, res.totalBytesExpectedToSend)              });          }      })

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

评论 抢沙发

E企盈小程序开发

联系我们联系我们

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

支付宝扫一扫打赏

微信扫一扫打赏