当前位置:网站首页>Wechat applet part of the mobile phone Preview PDF did not respond
Wechat applet part of the mobile phone Preview PDF did not respond
2022-04-23 19:08:00 【Gougouliang】
Today, my colleagues reported that , preview PDF Cannot be opened . Other colleagues can open .
After debugging with him, I found , Indicates that the cache is full .
adopt api FileSystemManager.readdir
Show him the cached files , Found to have 234 individual .
Let it clean up the cache , Preview normally PDF 了 .
Post the code
// preview PDF
previewPdf(params) {
uni.showLoading({
title: 'loading'
})
GetPhoto(params.filePath).then(res => {
uni.hideLoading()
if (res.statusCode == 400) {
this.$Toast(' file does not exist ')
return
}
let pdfBase64 = res.data
let fs = uni.getFileSystemManager();
fs.writeFile({
filePath: wx.env.USER_DATA_PATH + "/" + params.fileName + '.pdf',
data: uni.base64ToArrayBuffer(pdfBase64.replace(/[\r\n]/g, "")),
success: res => {
uni.openDocument({
filePath: wx.env.USER_DATA_PATH + "/" + params.fileName +
'.pdf',
showMenu: true,
success: function(res) {
},
fail(err) {
}
})
}
})
})
},
// Clean cache
removeFile() {
uni.showLoading({
title:' Cleaning up ...'
})
const fs = wx.getFileSystemManager()
fs.readdir({
dirPath: `${
wx.env.USER_DATA_PATH}/`,
success(res) {
let length = 0
for (let i of res.files) {
length++
if (length == res.files.length) {
setTimeout(()=>{
uni.hideLoading()
uni.showToast({
title: ' Clean up '
})
},500)
}
let name = (`${
wx.env.USER_DATA_PATH}/` + i)
if (name.indexOf('miniprogramLog') > -1) {
// No permission to delete skip
continue;
}
fs.unlink({
filePath: name,
fail(e) {
console.log(' File deletion failed :', e)
},
success(succ) {
console.log(' File deleted successfully :', succ);
}
})
}
},
fail(res) {
console.error(res)
}
})
},
版权声明
本文为[Gougouliang]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210602029749.html
边栏推荐
- WebView saves the last browsing location
- Introduction to ROS learning notes (I)
- static类变量快速入门
- Use bitnami / PostgreSQL repmgr image to quickly set up PostgreSQL ha
- Introduction to ROS learning notes (II)
- 【科普】CRC校验(一)什么是CRC校验?
- MySQL restores or rolls back data through binlog
- Sentinel service fusing practice (sentinel integration ribbon + openfeign + fallback)
- Coolweather is revised and connected to the wind weather interface to realize the broken line diagram of temperature
- 【历史上的今天】4 月 23 日:YouTube 上传第一个视频;网易云音乐正式上线;数字音频播放器的发明者出生
猜你喜欢
浅谈c语言指针的强制转换
Solutions such as unknown or garbled code or certificate problem prompt in Charles's mobile phone packet capture, actual measurement.
Esp32 drive encoder -- siq-02fvs3 (vscade + IDF)
Getting started with vcpkg
mysql通过binlog恢复或回滚数据
2022.04.23 (the best time for lc_714_to buy and sell stocks, including handling charges)
The first leg of the national tour of shengteng AI developer creation and enjoyment day was successfully held in Xi'an
Esp32 (UART receiving and sending) - receiving and sending communication of serial port (4)
Introduction to micro build low code zero Foundation (lesson 3)
[today in history] April 23: the first video uploaded on YouTube; Netease cloud music officially launched; The inventor of digital audio player was born
随机推荐
Dynamically add and delete layouts
C1000k TCP connection upper limit test 1
Nacos作为服务注册中心
Xlslib use
Deeply understand what new and make in golang are and what are the differences?
C: generic reflection
Get a list of recent apps
Raspberry pie uses root operation, and the graphical interface uses its own file manager
Partage de la conception de l'alimentation électrique de commutation et illustration des compétences en conception de l'alimentation électrique
从技术体系到商业洞察,中小研发团队架构实践之收尾篇
c1000k TCP 连接上限测试1
Go 语言 GUI 框架 fyne 中文乱码或者不显示的问题
Wechat video extraction and receiving file path
Use bitnami / PostgreSQL repmgr image to quickly set up PostgreSQL ha
How can programmers quickly develop high-quality code?
[play with lighthouse] Tencent cloud lightweight server builds a full platform video analysis video download website
特征选择feature_selection--SelectKBest
[popular science] CRC verification (I) what is CRC verification?
Sentinel服务熔断实战(sentinel整合ribbon+openFeign+fallback)
SSDB Foundation