Problem:
In my app, I want to access an image through cordova wkwebview. The HTML element looks as follows.
<img src="cdvfile://localhost/library-nosync/MyFolder/file.jpg">
While loading this, I get error "Failed to load resource: unsupported URL". I am working with iOS 10.2.
Things verified/tried:
If list of files present in "cordova.file.dataDirectory" under folder "MyFolder" is checked, I do see the "file.jpg" present there. It has the native URL as file:///var/mobile/Containers/Data/Application/app_id/Library/NoCloud/MyFolder/file.jpg.
I have added "img-src 'self' cdvfile: " to the Content-Security-Policy.
I have added following in the config.xml
<access origin="cdvfile://*" />
<allow-navigation href="cdvfile://*" />
<allow-intent href="cdvfile://*" />
<preference name="iosPersistentFileLocation" value="Compatibility" />
<preference name="iosExtraFilesystems" value="library,library-nosync,documents,documents-nosync,cache,bundle,root" />
There are no special (non-ASCII) characters in the URL as mentioned in threads relating to this error. What else could be the reason of "Unsupported URL"?.
Is the way I am accessing cdvfile:// path incorrect?
Update
I came across a link (forgot to capture that) saying the webview needs relative path and hence cdvfile:// would not work. I tried to change the image source to a relative path by changing it to "../../../../../../../../..//var/mobile/Containers/Data/Application/app-id/Library/NoCloud/MyFolder/file.jpg" and I could now see a new error - "Failed to load resource: The operation couldn’t be completed. Operation not permitted"
I could get the image working by "reading" the contents of the file and passing that base64 data as image source. But that is not how it should be, should it?