我在ionic 3(android(中从本地手机或sd卡存储、加载图像时出错
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
使用离子原生文件插件从文件系统读取base64
File.readAsDataURL(cordova.file.dataDirectory, fileUrl).then(imageBase64 => {
self.urlToShow = imageBase64;
});
对base64 url:进行消毒
get imageURLSanitized() {
return this.sanitizer.bypassSecurityTrustUrl(this.urlToShow);
}
在HTML中使用经过净化的url作为[src]
<img [src]=“imageURLSanitized”>