簡體   English   中英

離子-將圖像源設置為FILE_URI會產生:不允許加載本地資源錯誤

[英]Ionic - Setting an image source as FILE_URI produces: Not allowed to load local resource error

我目前正在使用Android,並通過Ionic開發我的應用。 當用戶拍照時,我會將其附加到離子幻燈片元素中的離子幻燈片上。 但是,我不斷收到“不允許加載本地資源錯誤”。 設置所有權限(保存圖像)

HTML:

<ion-slide *ngFor="let looImage of looImages">
  <img src="{{ looImage }}" imageViewer ion-long-press
       (onPressing)="showImageOptions()"/>
</ion-slide>

TS:

options: CameraOptions = {
  correctOrientation: true,
  quality: 50,
  destinationType: this.camera.DestinationType.FILE_URI,
  encodingType: this.camera.EncodingType.JPEG,
  mediaType: this.camera.MediaType.PICTURE
};

capturePhoto() {
  this.camera.getPicture(this.options).then((imageData) => {
  this.looImages.push(imageData);
  console.log(this.looImages.length);
}, (err) => {

});
}

完整錯誤:

不允許加載本地資源:file:///storage/emulated/0/Android/data/io.ionic.starter/cache/1538074314258.jpg

移動中的安全層拒絕從Web視圖加載圖像。 您可以使用“ DATA_URL”來返回base64內容。 您可以通過附加內容類型並應用DomSanitizer服務來附加到src屬性。

如果仍要使用FILE_URI,請使用ionic-native / file插件https://ionicframework.com/docs/native/file/ ,可以將圖像移到應用程序數據目錄中,然后從那里訪問。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM