[步骤]
选择手机中的本地图片,并上传
步骤:
选择手机中的本地图片,并上传
[结果]
选择上传的本地图片消失
[期望]
图片上传至服务器,本地图片保留
复现情况:
不是必现,无法确定触发条件,频率几十次会出现一次,是比较严重的问题
代码片段:
chooseImage: function(e) {
var _self = this
if (!_self.imageList) {
_self.imageList = []
}
wx.chooseImage({
count: _self.limit ? (_self.limit - _self.imageList.length) : 9,
sizeType: [‘compressed’], // original 原图,compressed 压缩图,默认二者都有
sourceType: [‘album’, ‘camera’], // 可以指定来源是相册还是相机,默认二者都有
success: function(e) {
_self.uploadimg(e)
},
})
},
uploadimg: function(data) {
let completeImages = 0
let _self = this,
keyname = _self.fileKeyName ? _self.fileKeyName : ‘upload-images’,
// imgs = _this.data.imgs,
// files = _this.data.files,
// count = _this.data.count,
storage = _self.storage,
i = data.i ? data.i : 0,
success = data.success ? data.success : 0,
fail = data.fail ? data.fail : 0
wx.uploadFile({
url: config.StorageUpload,
filePath: data.tempFilePaths[i],
formData: _self.formData,
name: keyname,
success: function(res) {
let _res = JSON.parse(res.data) //微信小程序返回必须要parse为json
if (_res.errno === 0) {
completeImages++
uni.showToast({
title: ‘上传进度:’ + completeImages + ‘/’ + data.tempFilePaths.length,
icon: ‘none’,
mask: false,
duration: 500
});
_self.storage.push(_res.data)
_self.imageList.push(data.tempFilePaths[i])
success++
}
},
fail: function(res) {
fail++
},
complete: function(res) {
i++
if (i == data.tempFilePaths.length) { //当图片传完时,停止调用
_self.$emit(‘add’, {
// currentImages: imagePathArr,
storage: _self.storage,
allImages: _self.imageList
})
_self.$emit(‘input’, _self.imageList)
} else {
data.i = i
data.success = success
data.fail = fail
_self.uploadimg(data)
}
}
})
},