详细问题描述
调用uni.chooseImage和uni.uploadFile上传手机本地照片后,会有部分本地的照片消失。复现过多次,但是复现的概率大概在几十次出现一次,或者有什么特殊条件触发。
[内容]
重现步骤
[步骤]
1.选择手机中的本地图片,并上传
- 图片上传至服务器
[结果]
选择的本地图片消失
[期望]
图片上传至服务器,本地图片保留
uni-app运行环境说明
[运行端是h5或app或某个小程序?]
微信小程序
[运行端版本号]
2.9.0
[项目是cli创建的还是HBuilderX创建的?如果是cli创建的,请更新到最新版cli再试]
HBuilderX创建
[编译模式是老模板模式还是新的自定义组件模式?]
新
[可重现代码片段]
selectImage: function() {
var _self = this
if (!_self.imageList) {
_self.imageList = []
}
uni.chooseImage({
count: _self.limit ? (_self.limit - _self.imageList.length) : 999,
success: function(e) {
var imagePathArr = e.tempFilePaths
//如果设置了limit限制,在web上count参数无效,这里做判断控制选择的数量是否合要求
//在非微信小程序里,虽然可以选多张,但选择的结果会被截掉
//在app里,会自动做选择数量的限制
if (_self.limit) {
var availableImageNumber = _self.limit - _self.imageList.length
if (availableImageNumber < imagePathArr.length) {
uni.showToast({
title: '图片总数限制为' + _self.limit + '张,当前还可以选' + availableImageNumber + '张',
icon: 'none',
mask: false,
duration: 2000
});
return
}
}
//检查服务器地址是否设置,设置即表示图片要上传到服务器
if (_self.serverUrl) {
uni.showToast({
title: '上传进度:0/' + imagePathArr.length,
icon: 'none',
mask: false
});
var remoteIndexStart = _self.imageList.length - imagePathArr.length
var promiseWorkList = []
var keyname = (_self.fileKeyName ? _self.fileKeyName : 'upload-images')
var completeImages = 0
for (let i = 0; i < imagePathArr.length; i++) {
promiseWorkList.push(new Promise((resolve, reject) => {
let remoteUrlIndex = remoteIndexStart + i
uni.uploadFile({
url: _self.serverUrl,
fileType: 'image',
formData: _self.formData,
filePath: imagePathArr[i],
name: keyname,
success: function(res) {
let _res = JSON.parse(res.data) //微信小程序返回必须要parse为json
if (_res.errno === 0) {
if (_self.isDestroyed) {
return
}
completeImages++
uni.showToast({
title: '上传进度:' + completeImages + '/' + imagePathArr.length,
icon: 'none',
mask: false,
duration: 500
});
console.log('success to upload image: ' + _res.data)
resolve(_res.data)
} else {
console.log('fail to upload image:' + _res.data)
reject('fail to upload image:' + remoteUrlIndex)
}
},
fail: function(res) {
console.log('fail to upload image:' + res)
reject('fail to upload image:' + remoteUrlIndex)
}
})
}))
}
Promise.all(promiseWorkList).then((result) => {
if (_self.isDestroyed) {
return
}
for (let i = 0; i < result.length; i++) {
_self.imageList.push(result[i])
}
_self.$emit('add', {
currentImages: imagePathArr,
allImages: _self.imageList
})
_self.$emit('input', _self.imageList)
})
} else {
for (let i = 0; i < imagePathArr.length; i++) {
_self.imageList.push(imagePathArr[i])
}
_self.$emit('add', {
currentImages: imagePathArr,
allImages: _self.imageList
})
_self.$emit('input', _self.imageList)
}
}
})
},
联系方式
[QQ]
76823823
0 个回复