wxhtmltopdf 图片路径问题_wx.openDocument无法读取文件 ,提示文件或文件夹不在白名单中,麻烦帮忙解答?...

wx.openDocument无法读取文件 ,提示文件或文件夹不在白名单中,麻烦帮忙解答?

我已经在开发者工具中勾选不检测域名选项,提示文件或文件夹不在白名单中,开发使用的基础库版本为2.11.1,已经尝试更换基础库版本,但是问题依旧未能得到解决。 wx.openDocument({      filePath: 'https://image.liangyikeji.net/test.pdf',      fileType: 'pdf',      success: function (res) {        console.log('打开文档成功')      }    })

I have checked the "do not detect domain name" option in the developer tool, indicating that the file or folder is not in the white list. The basic library version used for development is 2.11.1, and I have tried to change the basic library version, but the problem is still not solved. wx.openDocument ({      filePath: ' https://image.liangyikeji.net/test.pdf ',      fileType: 'pdf',      success: function (res) {         console.log ('Document opened successfully ')}})

回答:

Distance:

要先在后台配置downloadFile 域名,通过wx.downloadFile获取到本地临时路径,再调用wx.openDocument打开文件

Jie:好的,解决了,谢谢

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
如果您不想使用 `uni.openDocument` API 打开文件,您可以考虑使用其他方式打开文件,比如使用第三方插件或者自定义组件等。 以下是两个示例: 1. 使用第三方插件: 可以使用 uni-app 社区的一些第三方插件来实现打开文件的功能,例如 `uni-file-picker` 插件。这个插件可以选择文件并返回文件的本地路径,您可以使用这个路径来打开文件。 安装插件: ``` npm install uni-file-picker --save ``` 使用插件: ```javascript import filePicker from 'uni-file-picker' // 选择文件 filePicker.chooseFile({ success: (res) => { // res.tempFilePaths 为文件的本地临时路径 // 这里可以使用自己的方式打开文件 } }) ``` 2. 自定义组件: 您可以自定义一个组件来实现打开文件的功能。在组件,可以使用 `wx.chooseMessageFile` API 选择文件并返回文件的临时路径,然后使用 `wx.openDocument` API 打开文件。 组件示例: ```html <template> <button @click="openFile">打开文件</button> </template> <script> export default { methods: { openFile() { wx.chooseMessageFile({ count: 1, type: 'file', success: (res) => { wx.openDocument({ filePath: res.tempFiles[0].path, fileType: 'txt', success: () => { console.log('打开文件成功') }, fail: () => { console.log('打开文件失败') } }) }, fail: () => { console.log('选择文件失败') } }) } } } </script> ``` 注意:在使用 `wx.chooseMessageFile` 和 `wx.openDocument` API 时,需要将 `type` 和 `fileType` 参数设置为要打开的文件类型,这里以打开 txt 文件为例,需要将类型设置为 `file`,文件类型设置为 `txt`。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值