微信小程序 上传图片超过10个 以及解决uploadFile:fail exceed max upload connection count 10报错

比如:

在做项目的时候发现这个商品上传需要 最多传入18张图片

发现上传图片没限制但是报了一个错

uploadFile:fail exceed max upload connection count 10

然后去官方文档去看

这个就是最终的原因

  • requestuploadFiledownloadFile 的最大并发限制是 10 个;

图片上传 一般我是用的for循环 

一张一张上传导致了这个错误

想了一下 改了一下方法 最多18张图片都能上传成功了


var app = getApp();
Page({

 
  data: {
    img: 0,
    gid:''
  },
  //上传轮播图片
  upload(gid) {
    let that = this
    let store_id = that.data.shop.id //店铺id
    if (that.data.imagebox.length != 0) {
      let imagebox = that.data.imagebox
      for (let i = 0; i < imagebox.length; i++) {
        console.log('上传轮播图片', imagebox[i])
        wx.uploadFile({
          url: url,//并非真实接口
          filePath: that.data.imagebox[i],
          name: 'files',
          header: {
            "Content-Type": "multipart/form-data"
          },
          method: "POST",
          formData: {
            goods_id: gid,
            store_id: store_id
          },
          success: function(res) {
            console.log('轮播图片上传成功', res)
          },
          fail: function() {
            console.log('轮播图片上传失败')
          }
        })
      }
    } else {
      wx.showToast({
        title: '请上传图片',
      })
    }
  },



  //循环上传图片
  uploadDetail: function() {
    let that = this
    let imagebox = that.data.detailbox
    let gid = that.data.gid
    let img = that.data.img
    let length = parseInt(imagebox.length) + 1
    wx.uploadFile({
      url: url, //并非真实接口
      filePath: imagebox[img],
      name: 'files',
      header: {
        "Content-Type": "multipart/form-data"
      },
      method: "POST",
      formData: {
        goods_id: gid,
        type: 1
      },
      success: function(res) {
        console.log('success图片上传成功', res)
        if (true) {
          if (img == imagebox.length) {
            console.log("全部上传");
          } else {
            img++;
            that.setData({
              img: img
            })
            if (length == img) {
              console.log('停止上传')
            } else {
              that.uploadDetail();
            }
          }
        } else {
          //打印错误信息
          console.log("图片上传错误")
        }
      },
      fail() {
        console.log('上传详情失败')
      }

    })
  },





  onShow: function() {
 
  }
})

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值