如何在Ionic 4中使用img html标签显示缓存目录文件:///中的图像文件?

问题描述 投票:0回答:1

我正在尝试显示照片库中的图像。它返回我,file:///storage/emulated/0/Android/data/com.xxx.mobile/cache/20200306_121224.jpgHTML标签img不会呈现此路径。

。ts文件

const cameraOptions = {
      sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
      destinationType: this.camera.DestinationType.FILE_URI, 
      encodingType: this.camera.EncodingType.JPEG,
      correctOrientation: true
    }
      this.camera.getPicture(cameraOptions).then((imageData) => {
        if(imageData){
          this.filePath.resolveNativePath(imageData).then(filePath => {
            resolve(filePath);
            //filePath variable is 'file:///storage/emulated/0/Android/data/com.xxx.mobile/cache/20200306_121224.jpg'
          }).catch(err => console.log(err));

        }
      }, (err) => {
        var error = JSON.stringify(err)
        reject(error);
      })

。html文件

<img [src]="item.FileURI" />
cordova ionic4 filepath
1个回答
0
投票

替换

resolve(filePath);

with

resolve((<any>window).Ionic.WebView.convertFileSrc(filePath))

来源:https://forum.ionicframework.com/t/unable-to-display-image-using-file-uri/84977/25

© www.soinside.com 2019 - 2024. All rights reserved.