一个小小的问题困扰了我很久。。。
下面为小程序云开发获取云存储路径的过程:
//将图片临时路径上传到云端,并返回云端储存的路径,存放在 数组cloudtempFilePaths 中
var promiseArr = [];
var cloudFilePaths = [];
for (let i = 0; i < tempFilePaths.length; i++) {
var item = tempFilePaths[i];
var suffix = /\.\w+$/.exec(item)[0];//正则表达式返回文件的扩展名
wx.cloud.uploadFile({
cloudPath: new Date().getTime() + suffix, // 上传至云端的路径
filePath: item, // 小程序临时文件路径
success: res => {
console.log("返回的云端地址",res.fileID)//输出上传后图片的返回地址
cloudFilePaths.push(res.fileID);
}
})
}
console.log("cloudFilePaths", cloudFilePaths)
console.log("cloudFilePaths", cloudFilePaths[0])
结果如下
请问为什么控制台cloudFilePaths的[ ]里没有元素,而且为什么cloudFilePaths[0]为undefined呢?不应该是有值的吗?