uniapp微信小程序下载文件,保存文件功能总结

您所在的位置:网站首页 海信TLM32E29X程序文件下载 uniapp微信小程序下载文件,保存文件功能总结

uniapp微信小程序下载文件,保存文件功能总结

2024-05-23 23:02| 来源: 网络整理| 查看: 265

//通用下载文件方法 const download = (attachLink) => { let that = this uni.downloadFile({ url: attachLink , //下载地址,后端接口获取的链接 success: (data) => { console.log(data.tempFilePath) console.log(JSON.stringify(data)) if (data.statusCode === 200) { uni.saveFile({ //文件保存到本地 tempFilePath: data.tempFilePath, //临时路径 success: function(res) { console.log("下载成功"+res.savedFilePath) console.log(JSON.stringify(res)) uni.showToast({ icon: 'none', mask: true, title: '文件已保存!', duration: 3000, }); uni.openDocument({ //fileType: 'docx', showMenu:true, //关键点,可以转发到微信 filePath: res.savedFilePath, success: function(res) { console.log('打开文档成功'); } }); } }); } }, fail: (err) => { console.log(err); uni.showToast({ icon: 'none', mask: true, title: '失败请重新下载', }); }, }); }

先使用下载文件api把文件下载下来,再使用wx.openDocument() 打开文件里面加上showMenu字段,然后就可以看到在打开的文件右上角出现了···,就可以转发了 在这里插入图片描述 转载 https://blog.csdn.net/qq_37131884/article/details/123360114



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3