wx.openDocument
将wx.downloadFile下载的路径保存在storage里面,发现在iOS7 plus 和 iOS8中,
第一次走wx.downloadFile下载之后,先缓存起来,再用wx.openDocument打开时能够预览成功;
第二次是预览完后返回到小程序中,直接从缓存里面直接读取文件的缓存路径,用wx.openDocument打开却不行。
没有报错!
具体的表现是 在iOS7 plus出现频繁,iOS8中必现,其他机型上没发现问题
将wx.downloadFile下载的路径保存在storage里面,发现在iOS7 plus 和 iOS8中,
第一次走wx.downloadFile下载之后,先缓存起来,再用wx.openDocument打开时能够预览成功;
第二次是预览完后返回到小程序中,直接从缓存里面直接读取文件的缓存路径,用wx.openDocument打开却不行。
没有报错!
具体的表现是 在iOS7 plus出现频繁,iOS8中必现,其他机型上没发现问题
建议:
你可以在使用拉勾网 | 招聘求职找工作小程序,在 我的 -> 简历 -> 附件简历;这个预览是成功的;
使用拉勾面试百宝箱小程序(最好是借用一下你们公司面试官的账号,否则没有面试人信息),点击查看简历,这个预览就有问题了。
两个预览的逻辑都是一样的,现在第二个小程序就出问题了。。。
出现问题的机型:iOS7 plus,iPhone 8p iOS11; 微信版本 6.5.16
这个是预览简历:
previewFile: function(filePath, cb) { var that = this wx.openDocument({ filePath: filePath, success: function(res) { typeof cb == "function" && cb(); }, fail: function(e) { toast.basic.showToast({ title: '打开文件失败 :-)' }, that); }, complete: function(e){ console.log(e) } }); }, |
判断是否缓存中是否存在简历
var attachmentResumeCache = wx.getStorageSync('attachmentResumeCache') console.log("校验") console.log(attachmentResumeCache) var existResume = attachmentResumeCache[attachmentId] // 判断是否有缓存,有的直接从缓存中读 if(existResume){ wx.hideLoading() that.previewFile(existResume); }else{ /* 这一部分的代码是下载预览的 */ } }else{ wx.navigateTo({ url: `../resume/preview?name=${dataset.name}&resumeId=${dataset.resumeId}` }) } |
下载简历并且预览:
wx.downloadFile({ url: url, header: { 'Authorization': token }, dataType: "json", success: function(res) { var filePath = res.tempFilePath; attachmentResumeCache[attachmentId] = filePath; wx.setStorageSync('attachmentResumeCache', attachmentResumeCache); that.previewFile(filePath); }, fail: function() { toast.basic.showToast({ title: '下载附件简历失败 :-)' }, that); }, complete: function(e) { wx.hideLoading(); } }); |