当前位置:网站首页>小程序 读取文件
小程序 读取文件
2022-04-23 02:07:00 【逸曦穆泽】
序:由于小程序不可以直接读取程序包下文件的内容,所以把文件放到服务器上,使用下载获取文件到小程序,得到临时文件地址,并读取文件的内容
小程序读取文件的内容
getFileData(){
let that = this;
const fs = wx.getFileSystemManager()
let url = app.globalData.domain; // 请求域名路径
// 把服务器响应的文件下载到临时文件,根据需要读取文件的内容
wx.downloadFile({
url: url +'/api/otaNewFile', // 下载ota.hex文件
success (res) {
if (res.statusCode === 200) {
// 方法1 :读取文件信息
fs.readFile({
filePath: res.tempFilePath, // 获取的临时或本地文件路径
encoding: 'hex',
success(resd) {
that.setData({
otaData: resd.data
})
console.log("读取文件信息:",resd)
},
})
// 方法2 :读取文件信息
// let arrBuffer = fs.readFileSync(res.tempFilePath,'hex')
// console.log("读取文件信息:",arrBuffer)
}
}
})
},
期待后续...
版权声明
本文为[逸曦穆泽]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_41408081/article/details/124322319
边栏推荐
- Hyperscan -- 2 compilation
- Lane cross domain problem
- 配置iptables实现本地端口转发的方法详解
- 动态代理ip的测试步骤有哪些?
- How to choose a good dial-up server?
- Some tips for using proxy IP.
- PTA: 浪漫倒影 [二叉树重建] [深度优先遍历]
- World Book Day 𞓜 a good book that technicians should not miss (it cutting-edge technology)
- 007_Redis_Jedis连接池
- Network jitter tool clumsy
猜你喜欢

Wechat public platform test number application, authorized login function and single sign on using hbuilder X and wechat developer tools

Network jitter tool clumsy

Virtual serial port function of j-link V9 using skills

一些使用代理IP的小技巧。

一加一为什么等于二

Use of j-link RTT

002_Redis_String类型常见的操作命令

Is it better to use a physical machine or a virtual machine to build a website?
![App optimization and advanced scoreboard Part 2 [Mui + flask + mongodb]](/img/86/77b67fd28d2583e12f397430a9a62a.png)
App optimization and advanced scoreboard Part 2 [Mui + flask + mongodb]

搭建个人主页保姆级教程(二)
随机推荐
搭建个人主页保姆级教程(二)
What should I pay attention to when using proxy IP?
拨号vps会遇到什么问题?
BGP服务器在什么业务场景会被用到?
Is the availability of proxy IP equal to the efficiency of proxy IP?
002_Redis_String类型常见的操作命令
Why is one plus one equal to two
EBS:PO_EMPLOYEE_HIERARCHIES_ALL
动态代理ip的测试步骤有哪些?
What is a makefile file?
PTA: 点赞狂魔
Halo open source project learning (I): project launch
OJ daily practice - Finish
我国科学家揭示突破水稻产量瓶颈新机制
一些使用代理IP的小技巧。
2022.4.20-----leetcode. three hundred and eighty-eight
Gray scale range corresponding to colors (red, yellow, green, blue, purple, pink, brick red and magenta) in HSV color space
[leetcode daily question] 396 Rotation function
不断下沉的咖啡业,是虚假的繁荣还是破局的前夜?
Talk about biology live broadcast: Dr. Wang Ziyuan, a lake view biology, exploring hepatitis B with gene therapy