小程序
小游戏
企业微信
微信支付
扫描小程序码分享
云开发 替换文件(word)后 打开文件还是之前文件的内容,需要等个一分半钟左右的时间,再次打开,才会看到替换之后的内容;
例如:
原来的文件:1.docx(空) 打开后 文件为空
现在的文件:1.docx(有内容) 替换之后打开 文件还是空(后台替换之后的文件有内容)
等待一分半钟左右(什么都不操作)再次打开,文件有内容了
是wx.openDocument有延迟的问题吗
1 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
//查询用户缓存->打开文件->删除用户缓存文件
wx.getFileSystemManager().readdir({
dirPath:wx.env.USER_DATA_PATH,
success:function(res){
//console.log(res.files)
for (var i = 0; i<res.files.length; i++){
wx.getFileSystemManager().unlink({
filePath:wx.env.USER_DATA_PATH + '/' + res.files[i],
console.log('删除成功',res)
},
fail:function(err){
console.log(err)
}
})
that.download_file(e)//通过fileID下载文档
//通过fileID下载文档
download_file:function(e){
var that = this
var id = e.currentTarget.id//获取点击文档的下标id
var n = that.data.datalist[id].file_name_0;//通过下标id获取文件名称
const downloadTask = wx.cloud.downloadFile({
fileID: 'cloud://document-83jon.646f-document-83jon-1301145963/' + n ,//地址+名称
success: res => {
var address = res.tempFilePath ;
var code = res.statusCode;
wx.getFileInfo({
filePath:address,
success: res =>{
//console.log(res.size)
if(res.size < 10240000){
if(code == 200){
wx.getFileSystemManager().saveFile({
tempFilePath:address ,
filePath: wx.env.USER_DATA_PATH + "/" + n,
//预览文档
wx.openDocument({
filePath: wx.env.USER_DATA_PATH + "/" + n,//获取临时地址res.tempFilePath
showMenu:true,
that.setData({
loadingHidden:'false',
percent:'0'
console.log('打开成功!')
fail: res => {
console.log(res)
fail: err =>{
});
}else{
//console.log("size>10M")
filePath: address,//获取临时地址res.tempFilePath
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
//查询用户缓存->打开文件->删除用户缓存文件
wx.getFileSystemManager().readdir({
dirPath:wx.env.USER_DATA_PATH,
success:function(res){
//console.log(res.files)
for (var i = 0; i<res.files.length; i++){
wx.getFileSystemManager().unlink({
filePath:wx.env.USER_DATA_PATH + '/' + res.files[i],
success:function(res){
console.log('删除成功',res)
},
fail:function(err){
console.log(err)
}
})
}
that.download_file(e)//通过fileID下载文档
}
})
//通过fileID下载文档
download_file:function(e){
var that = this
var id = e.currentTarget.id//获取点击文档的下标id
var n = that.data.datalist[id].file_name_0;//通过下标id获取文件名称
const downloadTask = wx.cloud.downloadFile({
fileID: 'cloud://document-83jon.646f-document-83jon-1301145963/' + n ,//地址+名称
success: res => {
var address = res.tempFilePath ;
var code = res.statusCode;
wx.getFileInfo({
filePath:address,
success: res =>{
//console.log(res.size)
if(res.size < 10240000){
if(code == 200){
wx.getFileSystemManager().saveFile({
tempFilePath:address ,
filePath: wx.env.USER_DATA_PATH + "/" + n,
success: res =>{
//预览文档
wx.openDocument({
filePath: wx.env.USER_DATA_PATH + "/" + n,//获取临时地址res.tempFilePath
showMenu:true,
success: res => {
that.setData({
loadingHidden:'false',
percent:'0'
})
console.log('打开成功!')
},
fail: res => {
console.log(res)
}
})
},
fail: err =>{
console.log(err)
}
});
}
}else{
//console.log("size>10M")
wx.openDocument({
filePath: address,//获取临时地址res.tempFilePath
showMenu:true,