Как отобразить файл изображения из файла каталога кеша: ///, используя тег img html в ioni c 4? - PullRequest
0 голосов
/ 09 апреля 2020

Я пытаюсь отобразить изображение из библиотеки фотографий. Он возвращает меня, file:///storage/emulated/0/Android/data/com.xxx.mobile/cache/20200306_121224.jpg

HTML тег <img src="file:///storage/emulated/0/Android/data/com.xxx.mobile/cache/20200306_121224.jpg"/> недействителен.

Исходный код: .ts file

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 file

<img [src]="item.FileURI" />

1 Ответ

0 голосов
/ 09 апреля 2020

заменить

resolve(filePath);

на

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

источник: https://forum.ionicframework.com/t/unable-to-display-image-using-file-uri/84977/25

...