Not allowed to load local resource: file:///storage/emulated/0/Download/1533311989863.png ionic 3 (android)

▼魔方 西西 提交于 2021-01-29 09:58:04

问题


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>

I also tried,

path="file://storage/emulated/0/Download/1533311989863.png"

OutPut:-

Not allowed to load local resource: file:///storage/emulated/0/Download/1533311989863.png

回答1:


Read as base64 from filesystem using ionic-native File plugin:

File.readAsDataURL(cordova.file.dataDirectory, fileUrl).then(imageBase64 => {
self.urlToShow = imageBase64;
});

Sanitize the base64 url:

    get imageURLSanitized() {
    return this.sanitizer.bypassSecurityTrustUrl(this.urlToShow);

}

in HTML use sanitized url as [src]

<img [src]=“imageURLSanitized”>


来源:https://stackoverflow.com/questions/51676497/not-allowed-to-load-local-resource-file-storage-emulated-0-download-15333119

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!