小程序上传文件至云存储


 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,如果需要用到该文件就可以直接引用它了。

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM