云开发文件下载之后转发出现的问题

编程入门 行业动态 更新时间:2024-10-23 12:30:12

云开发<a href=https://www.elefans.com/category/jswz/34/1771438.html style=文件下载之后转发出现的问题"/>

云开发文件下载之后转发出现的问题

1、需要将云存储中的文件如:pdf/word/ppt/等 转发到微信群或好友

2、思路:云储存下载该文件并转发,同时显示下载进度条

share(url) {const downloadTask = wx.cloud.downloadFile({fileID: url,success: res => {let tempFilePath = res.tempFilePathwx.hideLoading()wx.shareFileMessage({filePath: tempFilePath,success(data) {wx.showToast({title: '转发成功',icon:'none'})},fileName: title,fail: e => {wx.showToast({title: '取消发送',icon:'none'})},})wx.showModal({title: '分享到',content: '文件下载完成,请选择要分享的对象',complete: (res) => {if (res.cancel) {wx.showToast({title: '分享取消',})}if (res.confirm) {wx.shareFileMessage({filePath: tempFilePath,success(data) {wx.showToast({title: '转发成功',icon:'none'})},fileName: title,fail: e => {wx.showToast({title: '取消发送',icon:'none'})},})}}})},fail: e => {wx.hideLoading()wx.showToast({title: '加载失败,请重试',icon:'none'})}})//下载进度条downloadTask.onProgressUpdate((res) => {if (res.progress === 100) {return} else {wx.showLoading({title: `正在下载...${res.progress}%`,})}})wx.hideLoading()}

出现的问题:
(1)开发工具不能实现测试功能;必须要真机调试;
(2)转发的文件是以 wxfile:// 开头,接收到的文件是没办法打开的;

2023.11.05 记录!

3、转变思路

文件下载后先打开预览,然后在右上角三点点击转发!

downloadAndShare(url) {const downloadTask = wx.cloud.downloadFile({fileID: url,success: res => {let tempFilePath = res.tempFilePathwx.hideLoading()//打开文件,预览之后即可转发wx.openDocument({filePath: tempFilePath,showMenu:true})}})//下载进度条downloadTask.onProgressUpdate((res) => {if (res.progress === 100) {return} else {wx.showLoading({title: `正在下载...${res.progress}%`,})}})wx.hideLoading()},

当然,为了减少用户的不断下载,可以设置缓存检查!

更多推荐

云开发文件下载之后转发出现的问题

本文发布于:2023-11-16 14:41:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1624560.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!