问题
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