wx.uploadFile一次性上传多图怎么弄啊?
发布于 6 年前 作者 chenqiang 13803 次浏览 来自 问答
wx.chooseImage({
  success: function(res) {
    var tempFilePaths = res.tempFilePaths//确定是一个多图的数组
    wx.uploadFile({
      url: 'http://192.168.11.168/kljjd/home/report/add/',
      filePath: tempFilePaths,//这里是多个不行, tempFilePaths[0]这样可以
      name: 'file[]',//我尝试这样写也不行
      formData:{
        'user': 'test'
      },
      success: function(res){
        util.debug(res);
      }
    })
  }
})
 
//控制台提示 WAService.js:1 uploadFile:fail parameter error: parameter.filePath should be String instead of Array;

别告诉我要循环多次一张张的上传啊?

10 回复

怎么递归的?串行的还是并行的?文档说可以最大并行10 怎么操作串行还是并行?

在success里面再去调用上传,安卓要多次调用

我按照上面写的代码,上传一张图片的话,苹果系统可以上传成功,但是android系统上传失败,提示fail:unknown,大神遇到过么

// 多图上传
choosePhoto(e){
  var that = this;
  wx.chooseImage({
    count: 6, // 默认9
    sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
    sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
    success: function (res) {
      // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
      var len = res.tempFilePaths.length;
      for(var i=0;i<len;i++){
        that.data.picLists.push(res.tempFilePaths[i])
      }
      var imgs = that.data.picLists.length;
      console.log(imgs)
      if (imgs >= 6) {
        that.data.aShow = true;
        that.data.picLists.length = 6
      }else{
        that.data.aShow = false;
      }
      that.setData({
        picLists: that.data.picLists,
        tShow: true,
        aShow: that.data.aShow
      })
      console.log(that.data.picLists)
    }
  })
},

1楼:是怎么循环解决的,方便贴出来看看吗?

回复3楼:我没遇到过这个问题,好像在百度上看到有人说过你这个问题,

谢谢大家啊,我估计也有只能循环了

递归暂时只能这样做了

建议你循环调用,我是这么解决了

回复3楼: 昨天刚遇到这个问题,formData传的参数需要encodeURI编码,服务端再解码。

异步循环有点麻烦,直接递归吧

回到顶部