离子-将图像源设置为FILE_URI会产生:不允许加载本地资源错误 [英] Ionic - Setting an image source as FILE_URI produces: Not allowed to load local resource error
问题描述
目前,我正在使用Android,并通过Ionic开发我的应用.当用户拍照时,我会将其附加到离子幻灯片元素中的离子幻灯片上.但是,我不断收到不允许加载本地资源错误".设置所有权限(保存图像)
I'm using Android at the moment and developing my app with Ionic. When a user takes a photo, I'm having it append to an ion-slide in a ion-slides element. However, I keep getting "Not allowed to load local resource error." All the permissions are set (The image gets saved)
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
Not allowed to load local resource: file:///storage/emulated/0/Android/data/io.ionic.starter/cache/1538074314258.jpg
推荐答案
移动设备中的安全层拒绝从Web视图中加载图像.您可以使用"DATA_URL"来返回base64内容.您可以通过附加内容类型并应用DomSanitizer服务来附加到src属性.
It's security layer in mobile which denies to load the image from web view. You can use 'DATA_URL' which will return base64 content. you can attach to src property by appending content type and applying DomSanitizer service.
如果您仍要使用FILE_URI,请使用ionic-native/file插件 https://ionicframework .com/docs/native/file/,则可以将图像移到应用程序数据目录中,然后可以从那里访问.
If you still want to use FILE_URI, using ionic-native/file plugin https://ionicframework.com/docs/native/file/, you can move the image in to application data directory and you can access from there.
这篇关于离子-将图像源设置为FILE_URI会产生:不允许加载本地资源错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!