uniapp 预览流文件pdf

开发中会遇到文件上传的类型功能,上传到对应的数据库了,可能用户需要下载回来保存预览和直接web预览的形式打开,下面来总结一下uniapp 预览流文件pdf的方式:
具体实现骨架屏方案:
第三方软件预览
webview打开
一、第三方软件预览
uni.downloadFile({ //通过uniapp的api下载下来url: 'test.pdf',success: function(res) {var filePath = res.tempFilePath;uni.openDocument({filePath: filePath,success: function(FileRes) {console.log('打开文档成功');}});}});
二、webview打开
export default {data() {return {src: '',allUrl: '',viewerUrl: '/hybrid/html/web/viewer.html',}},onLoad(options) {let fileUrl = encodeURIComponent("pdf的地址") // encodeURIComponent 函数可把字符串作为 URI 组件进行编码。this.allUrl = this.viewerUrl + '?file=' + fileUrl}}//然后就传路径到webViewuni.navigateTo({url: '../filePreview?url=' + 你的pdf路径})
评论
