不允许加载本地资源:file:///storage/emulated/0/Download/1533311989863.png ionic 3(android) [英] Not allowed to load local resource: file:///storage/emulated/0/Download/1533311989863.png ionic 3 (android)
本文介绍了不允许加载本地资源:file:///storage/emulated/0/Download/1533311989863.png ionic 3(android)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从本地电话或sd卡存储加载图像时,在ionic 3(android)中出现错误,
I got error in ionic 3(android) at load image on from local phone or sd-card storage,
path="file:///storage/emulated/0/Download/1533311989863.png"
<img [src]="path" > </img>
我也尝试过
path="file://storage/emulated/0/Download/1533311989863.png"
输出:-
Not allowed to load local resource: file:///storage/emulated/0/Download/1533311989863.png
推荐答案
使用ionic-native File插件从文件系统读取为base64:
Read as base64 from filesystem using ionic-native File plugin:
File.readAsDataURL(cordova.file.dataDirectory, fileUrl).then(imageBase64 => {
self.urlToShow = imageBase64;
});
清理base64网址:
Sanitize the base64 url:
get imageURLSanitized() {
return this.sanitizer.bypassSecurityTrustUrl(this.urlToShow);
}
在HTML中,使用经过消毒的url作为[src]
in HTML use sanitized url as [src]
<img [src]="imageURLSanitized">
这篇关于不允许加载本地资源:file:///storage/emulated/0/Download/1533311989863.png ionic 3(android)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文