当前位置:网站首页>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
边栏推荐
- Yyds dry goods inventory stringprep --- Internet string preparation
- ESP32 LVGL8. 1 - roller rolling (roller 24)
- Class loading process of JVM
- Coolweather is revised and connected to the wind weather interface to realize the broken line diagram of temperature
- Keysight has chosen what equipment to buy for you
- Sword finger offer II 116 Number of provinces - spatial complexity O (n), time complexity O (n)
- Using Visual Studio code to develop Arduino
- Practice of Druid SQL and security in meituan review
- JVM的类加载过程
- 解决:cnpm : 無法加載文件 ...\cnpm.ps1,因為在此系統上禁止運行脚本
猜你喜欢

Esp32 (UART 485 communication) - 485 communication of serial port (3)

PyGame tank battle

The difference between ordinary inner class and static inner class

OpenHarmony开源开发者成长计划,寻找改变世界的开源新生力!

七、DOM(下) - 章节课后练习题及答案

mysql_ Download and installation of Linux version

FTP、ssh远程访问及控制

JVM的类加载过程

Using Visual Studio code to develop Arduino

Introduction to ROS learning notes (I)
随机推荐
MySQL statement
開關電源設計分享及電源設計技巧圖解
Actual combat of Nacos as service configuration center
简化路径(力扣71)
Switching power supply design sharing and power supply design skills diagram
WebView opens H5 video and displays gray background or black triangle button. Problem solved
Screen right-click menu in souI
2022.04.23 (lc_763_divided into letter interval)
Minesweeping II of souI instance
Feature selection feature_ selection--SelectKBest
FTP、ssh远程访问及控制
How can programmers quickly develop high-quality code?
mysql_ Download and installation of Linux version
2022.04.23(LC_714_买卖股票的最佳时机含手续费)
Introduction to ROS learning notes (II)
Deeply understand what new and make in golang are and what are the differences?
Advanced transfer learning
[advanced level 11 of C language -- character and string functions and their simulation implementation (2)]
mysql_linux版本的下载及安装详解
Druid SQL和Security在美团点评的实践