javascript - 不允许加载本地资源 : Ionic3(ios)

标签 javascript file cordova camera ionic3

我遇到了这个问题

Not allowed to load local resource: 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 中我无法避免这个问题我确信这是由于一些安全问题如果有人帮助我会很棒。

最佳答案

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

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

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

iOS camera plugin returns source with protocol for new captures but when using it in your HTML to set the source of an element like img or video you need to remove protocol

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

希望对您有所帮助!

关于javascript - 不允许加载本地资源 : Ionic3(ios),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50206596/

相关文章:

javascript - js.erb 文件中的循环迭代频率是应有的两倍

javascript - 案例陈述一次引发多个警报

c# - While 循环仅对具有 4 个元素的数组进行两次迭代

javascript - 使用按钮垂直滚动 div

ajax - 电话间隙 : cookie based authentication (PHP) not working [webview]

javascript - 无法获取动态添加的文本区域的 outerHTML/值

Javascript:在另一个延迟函数中调用延迟函数

java - 从我刚刚创建的文件中获取 Uri (android)

python - 加载一个文件 python

javascript - Cordova 应用程序中 HTML 元素中存储的数据的有效性