img标签显示不了file以及cdvfile协议的图片

如题,img标签的src指定file或者cdvfile协议的图都显示不了,但是http的可以,已经配置了compileProvider白名单

<!-- 图片显示不了 -->
<img src="cdvfile://localhost/temporary/1443066824077.jpg" alt="" style="max-width: 100%">
<img src="file://......" alt="" style="max-width: 100%">
$compileProvider.imgSrcSanitizationWhitelist(/^\s(https|file|blob|cdvfile):|data:image\//)

图片路径是没问题的,因为可以在手机浏览器直接访问(cdvfile的当然不行啦)

运行环境:

手机:nexus 6
系统:clipboard.png

阅读 9k
3 个回答

试一试window.Ionic.WebView.convertFileSrc这个方法.
ionic网站如下记述:

Cordova and Capacitor apps are hosted on a local HTTP server and are served with the http:// protocol. Some plugins, however, attempt to access device files via the file:// protocol. To avoid difficulties between http:// and file://, paths to device files must be rewritten to use the local HTTP server. For example, file:///path/to/device/file must be rewritten as http://&lt;host>:<port>/<prefix>/path/to/device/file before being rendered in the app.
For Cordova apps, the Ionic Web View plugin provides a utility function for converting File URIs: window.Ionic.WebView.convertFileSrc(). There is also a corresponding Ionic Native plugin: @ionic-native/ionic-webview.

参考以下网站:

https://forum.ionicframework....

https://beta.ionicframework.c...

https://github.com/devomair/f...

经过测试,最后使用了插件webview,问题解决.

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进