当前位置:网站首页>小程序 读取文件
小程序 读取文件
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
边栏推荐
猜你喜欢
Micro build low code zero foundation introductory course
What is a dial-up server and what is its use?
How to set computer IP?
[tutorial] how to use GCC "zero assembly" for white whoring MDK
What categories do you need to know before using proxy IP?
arduino esp8266 网络升级 OTA
89 logistic回歸用戶畫像用戶響應度預測
PTA: 浪漫倒影 [二叉树重建] [深度优先遍历]
RuntimeError: The size of tensor a (4) must match the size of tensor b (3) at non-singleton dimensio
校园转转二手市场源码
随机推荐
一加一为什么等于二
[hands on learning] network depth v2.1 Sequence model
Leetcode46 Full Permutation
What business scenarios will the BGP server be used in?
What businesses use physical servers?
Multithreading technology core
有哪些业务会用到物理服务器?
2022.4.22-----leetcode.396
Nanny level tutorial on building personal home page (II)
ThinkPHP kernel development blind box mall source code v2 0 docking easy payment / Alibaba cloud SMS / qiniu cloud storage
RuntimeError: The size of tensor a (4) must match the size of tensor b (3) at non-singleton dimensio
LeetCode 349. Intersection of two arrays (simple, array) Day12
Log4j2 configuration
89 logistic回归用户画像用户响应度预测
What are the common proxy IP problems?
LeetCode 447. Number of boomerangs (permutation and combination problem)
浅析一下隧道代理IP的优缺点。
009_Redis_RedisTemplate入门
Redis memory recycling strategy
89 logistic回歸用戶畫像用戶響應度預測