【问题标题】: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)
【发布时间】:2018-08-03 16:11:06
【问题描述】:

在从本地手机或 sd 卡存储加载图像时,我在 ionic 3(android) 中遇到错误,

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-framework ionic3


    【解决方案1】:

    使用 ionic-native File 插件从文件系统读取为 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”>
    

    【讨论】:

      猜你喜欢
      • 2019-02-02
      • 2021-11-05
      • 2023-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多