当前位置: 首页 > news >正文

uniapp获取 pdf文件流 并展示

1、流数据
uni.request({
url: this.$config.apiUrl+“/api/report/content/fill?code=bv.mf.refund.pay.voucher&busiNo=00201323051500148949”,
header: {
‘content-type’: ‘application/json;charset=utf-8’,
‘X-App-Code’: ‘weixin’,
‘X-Source’: ‘program’,
‘X-Token’: store.getters.token
},
responseType:‘arraybuffer’,
success: (data) => {
const fs = uni.getFileSystemManager()
const filePath = wx.env.USER_DATA_PATH + ‘/’ + Date.now() + ‘.pdf’ // wx.env.USER_DATA_PATH 为微信提供的保存文件路径
console.log(filePath)
fs.writeFile({
filePath,
data: data.data, // 将 base64 转为 arrayuffer wx.base64ToArrayBuffer(res.replace(/[\r\n]/g, ‘’))
success (res) {
uni.openDocument({
showMenu: true,
fileType: ‘pdf’,
filePath,
success: function (res) {
console.log(‘打开文档成功’)
}
})
},
fail (err) {
console.log(‘错误’, err)
}
})
}
});
2 文件地址模式

        uni.showLoading({title: '下载中'});//下载文件uni.downloadFile({ //只能是GET请求url:  this.$config.apiUrl+"/api/report/content/fill?code=bv.mf.refund.pay.voucher&busiNo=00201323051500148949", //请求地址(后台返回的码流地址)// url: this.$config.staticUrl+"/emptyOwner.png",success: (res) => {//下载成功if (res.statusCode === 200) {//保存文件let tempFile = res.tempFilePath;//保存成功之后 打开文件uni.getFileSystemManager().saveFile({tempFilePath: tempFile,// filePath: wx.env.USER_DATA_PATH + '/' + '上传成员.pdf',//自定义文件名success(res) {console.log(res)uni.openDocument({filePath: res.savedFilePath,showMenu: true, //是否可以分享success: (res) => {uni.hideLoading()console.log(res);},fail: (e) => {uni.showToast({title: '打开失败',icon: "error"})}})}})}},fail: (e) => {console.log(e, '文件下载失败')uni.showToast({title: '文件下载失败',icon: "error",})}});
http://www.lryc.cn/news/144114.html

相关文章:

  • Linux(进程间通信)
  • Go的Gorm数据库操作错误WHERE conditions required
  • 基于java swing和mysql实现的仓库商品管理系统(源码+数据库+运行指导视频)
  • 6、css学习6(表格)
  • Ceph源码解析:PG peering
  • 解决jupyter notebook可以使用pytorch而Pycharm不能使用pytorch的问题
  • 对建造者模式理解
  • 回归预测 | MATLAB实现CSO-ELM布谷鸟算法优化极限学习机多输入单输出回归预测(多指标,多图)
  • 静态链接库和动态链接库的区别
  • 使用 python 源码搭建 conda 环境
  • dart 学习之 异步操作
  • 《Flink学习笔记》——第二章 Flink的安装和启动、以及应用开发和提交
  • 网易新财报:游戏稳、有道进、云音乐正爬坡
  • Docsify的评论系统gitalk配置过程
  • HarmonyOS/OpenHarmony(Stage模型)卡片开发应用上下文Context使用场景二
  • 数字货币量化交易平台
  • 2022 ICPC 济南 E Identical Parity (扩欧)
  • 【BUG事务内消息发送】事务内消息发送,事务还未结束,消息发送已被消费,查无数据怎么解决?
  • 数据分析作业四-基于用户及物品数据进行内容推荐
  • 在腾讯云服务器OpenCLoudOS系统中安装svn(有图详解)
  • C语言日常刷题5
  • 【LeetCode-中等题】73. 矩阵置零
  • 本地部署 FastGPT
  • 软件工程(十八) 行为型设计模式(四)
  • Socket通信与WebSocket协议
  • 新KG视点 | Jeff Pan、陈矫彦等——大语言模型与知识图谱的机遇与挑战
  • 详解过滤器Filter和拦截器Interceptor的区别和联系
  • List常用的操作
  • Android studio APK切换多个摄像头(Camera2)
  • ChatGPT 对教育的影响,AI 如何颠覆传统教育