1

I'm using capacitor Filesystem plugin in order to write and read files in capacitor mobile app. On IOS, I'm using FilesystemDirectory.Documents as directory param when writing files and folders. When I call Filesystem.getUri({ path: directoryPath, directory:FilesystemDirectory.Documents }), instead of returning the full path (file://...), it is returning the '/DOCUMENTS/...' and I can't use the returned url to load the file.

Noting that it is working perfectly on android and electron app. Any help regarding IOS?

2 Answers2

1

I had a similar issue to that, turned out it was due to App-Bound Domains being enabled. When it is the case, it is the web version running there. As mentioned by @jcesarmobile in this comment:

Adding WKAppBoundDomains key blocks JavaScript injection and other WKWebView features unless limitsNavigationsToAppBoundDomains is set to true ... Without the JavaScript injection, native plugins don't work and the web version is used instead.

Web version uses relative URIs like /DOCUMENTS/... as files are stored into browser's IndexedDb and there is no way to get a full path to them. (At least at this writing time, see this related open issue).

If it is the case, either remove that key and disable App-Bound Domains or set limitsNavigationsToAppBoundDomains to true and Filesystem.getUri(..) will return a path starting with file://. Pass it into Capacitor.convertFileSrc(..) and you'll get a working url wtarting with capacitor://localhost/_capacitor_file_/.. that your DOM can consume.

Salem Ouerdani
  • 7,596
  • 3
  • 40
  • 52
  • Hello I'm running into the same issue but I don't have anything about App-Bound Domains in my config. I'm running Capacitor 2.4.6 on iOS in local development with livereload (its working when livereload is disabled). Any idea why ? – benuuts Nov 22 '21 at 12:48
  • No idea @benuuts. I did not use any live reloading so my best guess would be that the live reload tool you are using, is internally bounding the web app version instead of the compiled code. I'd check its documentation and settings or try a different library/tool if possible. – Salem Ouerdani Mar 25 '22 at 16:21
0

As in IOS, your app is running in a sandboxed environment as described here What is the documents directory (NSDocumentDirectory)? an so IOS will create for each app a seperate file system with one of its directories the /DOCUMENTS/ that we have here so it is a normal behavior that this is the path you get. (It is also described here https://capacitorjs.com/docs/apis/filesystem#filesystemdirectory) Can you please specify what exactly you need the full path for as your app can access its own /DOCUMENTS/ directory but not others app /DOCUMENTS/.

Michael
  • 17
  • 5
  • I am writing some files in the documents directory, and I need to get the full path of these files so I can pass it to plugins, such as cordova fileopener or Media plugin,... – user14608530 Nov 11 '20 at 14:12