当前位置:网站首页>微信小程序打开文件流
微信小程序打开文件流
2022-06-29 08:26:00 【swag_特约男演员】
接收后台返回的文件流并打开
// 预览文件
topreFile(url, name) {
wx.showLoading({
title: '加载中'
})
wx.request({
url: downloadFile, // 请求地址
data: {
fileUrl: url, fileName: name }, // 请求参数
method: 'GET',
header: {
// 根据自己需求设定
'Content-Type': 'application/json',
'X-Access-Token': wx.getStorageSync('token'),
req_type: 'xcx'
},
responseType: 'arraybuffer', //此处是请求文件流,必须带入的属性
success: res => {
if (res.statusCode === 200) {
const fs = wx.getFileSystemManager() //获取全局唯一的文件管理器
fs.writeFile({
filePath: wx.env.USER_DATA_PATH + '/' + `${
name}`, // wx.env.USER_DATA_PATH 指定临时文件存入的路径,后面字符串自定义(一定要加“/”)
data: res.data,
encoding: 'binary', //二进制流文件必须是 binary
success(res) {
wx.openDocument({
// 打开文档
filePath: wx.env.USER_DATA_PATH + '/' + `${
name}`, //拿上面存入的文件路径(一定要加“/”)
showMenu: true, // 显示右上角菜单
success: function(res) {
setTimeout(() => {
wx.hideLoading()
}, 500)
}
})
}
})
}
}
})
}
鸣谢
边栏推荐
- 2022第六季完美童模 海口赛区 选拔赛圆满落幕
- The @dynamicmemberlookup and callasfunction features in swift implement the object transparent proxy function
- MYSQL行转列例子
- Tutorial on building open source Internet of things platform
- mongoDB 持久化
- CDGA|交通行业做好数字化转型的核心是什么?
- 闭关修炼(二十五)基础web安全
- 首次触电,原来你是这样的龙蜥社区 | 龙蜥开发者说第8期
- verilog 归约操作符
- 开发小技巧-图片资源管理
猜你喜欢
随机推荐
Intelligent hardware EVT DVT PVT mp
802.11--802.11n protocol phy
MYSQL行转列例子
Huawei equipment is configured with medium-sized network WLAN basic services
The return values of hostname -f and uname -n may be different
积分商城运营要如何做才能获取到利润
Déclaration de la variable Typescript - - assertion de type
PointNet/Pointnet++训练及测试
MySQL virtual column
MYSQL虚拟列
ES6 data type map & set
[most complete] download and installation of various versions of PS and tutorial of small test ox knife (Photoshop CS3 ~ ~ Photoshop 2022)
(III) encoder self attention mask
Verilog data type
sql server 用 administrator 权限运行吗?还是以普通用户运行呢?
航芯开发板&调试器
verilog 归约操作符
Enrollment brochure for system integration project management engineer certification in July 2022
2022第六季完美童模 合肥賽區 决賽圓滿落幕
Using scan in redistemplate




![[untitled]](/img/6e/5dd5dcff89a74f7d367c9186a77268.png)




