首页 > 解决方案 > 不允许加载本地资源:Ionic3(ios)

问题描述

我收到了这个问题

不允许加载本地资源:file:///var/mobile/Containers/Data/Application/AB6EABD9-CAAF-4AE5-91F9-D8042B34EA87/tmp/cdv_photo_002.jpg

我的代码看起来像

let cameraOptions = {
      quality: 50,
      destinationType: this.camera.DestinationType.FILE_URI,
      encodingType: this.camera.EncodingType.JPEG,
      mediaType: this.camera.MediaType.PICTURE
    }

this.camera.getPicture(cameraOptions).then((imageData) => {
   this.myImage = imageData;
})

在 android 设备中它工作正常,但在 ios 中我无法避免这个问题,我确信这是由于一些安全问题,有人帮助我会很棒。

标签: javascriptfilecordovacameraionic3

解决方案


我认为这样的事情可能对你有用:

if (isIos()) {
  itemSrc = itemSrc.replace(/^file:\/\//, '');
}

基于我看到的另一个线程:

iOS 相机插件返回带有新捕获协议的源,但是在 HTML 中使用它来设置 img 或 video 等元素的源时,您需要删除协议

你可以在这里阅读更多信息:Ionic 3: File_URI Not allowed to load local resource IOS

我希望这会有所帮助!


推荐阅读