小程序之云存储和云函数
2020-06-06 本文已影响0人
拾杉
效果图:
image.png
xml:
<button type="primary" style="margin-top:20px;"
bindtap="upload">上传文件</button>
<button type="primary" style="margin-top:20px;"
bindtap="download">下载文件</button>
<button type="primary" style="margin-top:20px;"
bindtap="delete">删除文件</button>
js:
delete:function(){
wx.cloud.deleteFile({
fileList:['cloud://cloud-58lf0.636c-cloud-58lf0-1302202484/test.jpg'],
success:res=>{
console.log('删除成功')
console.log(res)
},
fail:err=>{
console.log(err)
}
})
},
download:function(){
wx.cloud.downloadFile({
fileID:'cloud://cloud-58lf0.636c-cloud-58lf0-1302202484/test.jpg',
success:res=>{
console.log(res)
console.log('下载成功')
wx.saveImageToPhotosAlbum({
filePath: res.tempFilePath,
success:res=>{
console.log('存储图片至系统相册成功')
console.log(res)
},
fail:err=>{
console.log(err)
}
})
}
})
},
upload:function(){
console.log('上传文件开始')
wx.chooseImage({
success:function(res){
console.log(res.tempFilePaths[0])
wx.cloud.uploadFile({
cloudPath:'test.jpg',
filePath:res.tempFilePaths[0],
success:res=>{
wx.showToast({
title:'上传成功',
})
},
fail:err=>{
console.log(err)
}
})
}
})
},