首页 > 解决方案 > 显示 ERR_INVALID_URL 的离子图片

问题描述

嗨 ionic,我正在尝试显示图片,但出现 ERR_INVALID_URL 错误。这是代码

 resimekle()
  {
    const options: CameraOptions = {
      quality: 100,
      destinationType: this.camera.DestinationType.FILE_URI,
      encodingType: this.camera.EncodingType.JPEG,
      mediaType: this.camera.MediaType.PICTURE
    }
    
    this.camera.getPicture(options).then((imageData) => {
     // imageData is either a base64 encoded string or a file URI
     // If it's base64 (DATA_URL):
     this.base64Image = 'data:image/jpeg;base64,' + imageData;
     this.base64Image= this.base64Image.replace(/^file:\/\//, '');
    }, (err) => {
     // Handle error
    });
  }

<img [src]="_DomSanitizationService.bypassSecurityTrustUrl(base64Image)"/>

错误:data:image/jpeg;base64,file:///storage/emulated/0/Android/data/io.ionic.starter/cache/1542647016224.jpg net::ERR_INVALID_URL

标签: imageionic-frameworkcamerabase64

解决方案


使用文件插件如下。

    this.file.readAsDataURL(path, fileName).then(imageBase64 => {
        this.picture = imageBase64;
      });

 <img src="{{picture}}">

推荐阅读