2025-07-04 openDocument:fail NOT_WHITELIST_FILE: no such file
情况1:调用uniapp打开文档接口:
uni.openDocument({ filePath: url, fileType: 'pdf', showMenu: true, success: (open) => { console.log('打开成功') }, fail: (err) => { console.log('打开失败',err) } })
打开失败并报错:
{ errMsg:"openDocument:fail NOT_WHITELIST_FILE: no such file or directory xxx链接" }
请确保你的xxx链接能够在浏览器端正常打开,并且!!传给这个方法的url必须是从wx.downloadFile返回的文件路径,也就是说你的代码应该是这样的:
wx.downloadFile({ url: url, success(res) { const tempFilePath = res.tempFilePath; wx.openDocument({ filePath: tempFilePath, fileType: 'pdf', success: function () { console.log('成功打开 PDF'); }, fail: function (err) { console.error('打开失败:', err); } }); }, fail(err) { console.error('下载失败:', err); } });
不然就会出现标题的错误
情况2:你的路径没有在小程序域名白名单那里配置
其实上面说的都不是很正确,首先你想用openDocument这个方法,那么就得了解它接受的路径是本地路径,你扔给它一个网络链接怎么打得开呢,其次你要获取本地路径就得用downloadFile把这个网络链接下载下来,注意,你得给downloadFile配置合法域名,不然也是下载不了的,配置好后才没有什么白名单的报错,完成这几步才能顺利打开网络链接对应的文件,understand?

浙公网安备 33010602011771号