1 addImg:function(){ 2 wx.chooseImage({ 3 success: function(res) { //chooseImage方法調用成功 4 console.log(res); 5 6 wx.cloud.uploadFile({ 7 cloudPath:"funny/mbp.jpg", 8 filePath: res.tempFilePaths[0], 9 success(res){ //上傳至雲存儲后 10 console.log(res); 11 } 12 }) 13 }, 14 }) 15 }
第四行的console.log(res) , 打印后可以看到一個tempFilePaths數組,tempFilePaths是圖片的本地臨時文件路徑列表
那么tempFilePaths[0]就是具體的文件路徑。
第二個res是上傳文件upLoadFile后的,打印時會看到上傳成功后在雲存儲的fileID,如果需要用到該文件就可以直接引用它了。