10

Im using the camera to take an image and preview it. It needs to be sent to a server so Im using the destination type of 'FILE_URI'. It works when I run it on android, but Im getting this error running it on ios 10.3.1

Not allowed to load local resource : file:///var/mobile/Containers/Data/Application/2CE518F3-4F4E-42A9-94E1-DC06D01250C7/tmp/cdv_photo_001.jpg

I am not running it with the -lc tag. The encoding type is JPEG

Alessandro Kreslin
  • 269
  • 1
  • 3
  • 15
  • DId you try any of these steps? https://stackoverflow.com/questions/38795550/not-allowed-to-load-local-resource-for-local-image-from-remote-page-in-phonega – Andreas Gassmann Jul 04 '17 at 21:17
  • yes I did, but with using Angular/Ionic it gives warnings about how it was unsafe and sanitized the url making it unusable. I tried to bypass it using the DomSanitizer but nothing was working – Alessandro Kreslin Jul 04 '17 at 21:48
  • Try this: this question will help you. https://stackoverflow.com/questions/53395712/ionic-angular-4-0-0-beta-13-not-allowed-to-load-local-resource-with-webview/53414202#53414202 – Ashish Patidar Nov 22 '18 at 06:40

4 Answers4

22

I was facing same problem and I realized that in 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... So I did :

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

If you want to move capture to somewhere else restore protocol or make a copy beforehand or whatever

Hope it helps

  • This fixes the iOS issue and doesn't cause any issues when applied to Android as well. Thanks! – tanz Feb 14 '18 at 21:29
5

I was running the app in livereload mode and facing the same problem and I tried this answer, changing from livereload to normal mode solved the problem.

It should help you as helped me, at least for now.

4

use this path = normalizeURL(path); and also read more about WKWebView

Junaid
  • 4,682
  • 1
  • 34
  • 40
3

With ionic webview 2.4.1+, you have to use window.Ionic.WebView.convertFileSrc(url);, see https://stackoverflow.com/a/54416951/1805493

Liam Mazy
  • 390
  • 3
  • 15