话不多说,直接上代码:
wxml页面:
<view bindtap="chooseFile">上传</view>
js页面:
//第一步:选择文件chooseFile(){let that = thiswx.chooseMessageFile({count: 1,type: 'all', // all 代表所有类型的文件都可以上传success (res) {wx.showLoading({title: '上传中...',});// tempFilePath可以作为img标签的src属性显示图片const tempFilePaths = pFileslet tempFile = tempFilePaths[0]that.uploadFile(tempFile.name,tempFile.path)}})},//第二步:通过uploadFile上传选中的文件uploadFile(fileName,tempFile){wx.cloud.uploadFile({cloudPath:fileName,filePath:tempFile,}).then(res=>{console.log("上传成功啦",res);wx.hideLoading()wx.showToast({title: '文件上传成功',icon:"success",duration:2000})}).catch(err=>{console.log("上传失败啦",err);})}
本文发布于:2024-01-30 23:23:00,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170662817923578.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |