怎么上传多个图片呢 急
发布于 5 年前 作者 leiwan 19121 次浏览 来自 问答

为什么上传就一个图片呢 不能上个多图片呢?

10 回复

wxml是

 <image src="{{src}}"   controls ></image>

  <view class=“btn-area”>

    <button bindtap=“bindButtonTap”>上传图片</button>

  </view>

</view>

wx.chooseImage({
                        success: function (res) {
                            for (let index in res.tempFilePaths) {
                                that.uploadFile(res.tempFilePaths[index]).then(function (resolve) {
                                    let thumbPath = that.data.thumbPath;
                                    let thumb = that.data.thumb;
                                    thumbPath.push(resolve);
                                    thumb.push(app.baseUrl + resolve);
                                    that.setData({
                                        thumbPath: thumbPath,
                                        thumb: thumb
                                    });
                                }, function (reject) {
                                    console.log(reject);
                                })
                            }
                            wx.hideLoading();
                        }
                    })

这for循环还是拉倒吧

@You can you up 官方API只有单个文件上传,并且最多并发10个

@You can you up 你有更好的办法可以分享下.

@厚光  我也想知道   二楼不是说知道么

for循环 方法也是每次上传一次  多次上传而已  会有很多问题

文件地址支持数组就好了

@不忘初心@小糖糖

能给我发下不  万分感激     谢谢了!!!

upload:function(){

  var that=this

  wx.chooseImage({

    count: 9, 

    sizeType: [‘original’, ‘compressed’], 

    sourceType: [‘album’, ‘camera’], 

    success: function (res) {

      var tempFilePaths = res.tempFilePaths

      console.log(tempFilePaths)

      wx.uploadFile({

        url: ‘file_upload.php’, 

        filePath: tempFilePaths[0],

        name: ‘file’,

        formData:{

          ‘user’: ‘test’

        },

        success: function(res){

          var data = res.data

          wx.showModal({

            title: ‘上传文件返回状态’,

            content: ‘成功’,

            success: function(res) {

              if (res.confirm) {

                console.log(‘用户点击确定’)

              }

            }

          }) 

          const uploadTask = wx.uploadFile({

            url: ‘file_upload.php’, //仅为示例,非真实的接口地址

            filePath: tempFilePaths[0],

            name: ‘files’,

            formData:{

              ‘user’: ‘test’

            },

            success: function(res){

              var data = res.data

                //do something

              }

            })

          uploadTask.onProgressUpdate((res) => {

            that.setData({

              progress:res.progress

            })

            console.log(‘上传进度’, res.progress)

            console.log(‘已经上传的数据长度’, res.totalBytesSent)

            console.log(‘预期需要上传的数据总长度’, res.totalBytesExpectedToSend)

          })

        uploadTask.abort() // 取消上传任务                         

      },

      fail:function(res){

        console.log(res)

      }

    }),

      that.setData({

        path:tempFilePaths

      })  

    }

  })

},

不就是,chooseImage多个图片后,保存返回的多个图片地址。后面自己做批量上传

@不忘初心  怎么做

回到顶部