比如:
在做项目的时候发现这个商品上传需要 最多传入18张图片
发现上传图片没限制但是报了一个错
uploadFile:fail exceed max upload connection count 10
然后去官方文档去看
这个就是最终的原因
request
、uploadFile
、downloadFile
的最大并发限制是 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() {
}
})