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]就是具体的文件路径。

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

 

第二个res是上传文件upLoadFile后的,打印时会看到上传成功后在云存储的fileID,如果需要用到该文件就可以直接引用它了。

 

 小程序上传文件至云存储 随笔

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄