wx.cloud.getTempFileURL成功获取到数组https链接后,后台会重复生成一个没有picurl的表
var pathArr = [];
var formData = {};
if (this.data.tempPath.length) {
this.data.tempPath.forEach((item, idx) => {
var title = res.detail.value.title;
var file = common.getMyId()
var filename = common.getMyFile(item)
this.uploadFile(filename, item)
})
} else {
this.pushCloud(formData)
}
},
uploadFile(filename, path) {
wx.cloud.uploadFile({
cloudPath: filename,
filePath: path
}).then(res => {
this.getImgUrl(res.fileID)
})
},
getImgUrl(fileID) {
wx.cloud.getTempFileURL({
fileList: [fileID],
}).then(res => {
pathArr.push(res.fileList[0].tempFileURL)
if (pathArr.length == this.data.tempPath.length) {
formData.picurl = pathArr
}
this.pushCloud(formData)
})
},
帮忙看下哪里错了,怎么改
async await promise 学学就解决了
Page({
data: {
tempFiles: []
},
chooseImage: function() {
wx.chooseMedia({
count: 9,
mediaType: ['image'],
success: res => {
this.setData({
tempFiles: res.tempFiles
})
}
})
},
async submit() {
let arr = [];
for(let i = 0; i < this.data.tempFiles.length; i += 1) {
let tempUrl = await this.uploadFile(this.data.tempFiles[i].tempFilePath);
console.log("获取临时地址:" + tempUrl)
arr.push(tempUrl);
}
console.log(arr)
// 调用云函数
},
uploadFile(filePath) {
return new Promise((reslove, reject) => {
wx.cloud.uploadFile({
cloudPath: "demo/" + new Date().getTime() + ".jpg",
filePath: filePath
}).then(res => {
wx.cloud.getTempFileURL({
fileList: [res.fileID]
}).then(res => {
reslove(res.fileList[0].tempFileURL);
})
})
});
}
})