Open ThomasKientz opened 4 years ago
can you provide a sample app?
@jcesarmobile I made further tests. Crash only occurs with paths starting content://
. I got those paths from an intent (https://github.com/darryncampbell/darryncampbell-cordova-plugin-intent#intentshimonintent)
Here is a sample app : https://github.com/ThomasKientz/capacitor-fs-issue-repro
Yeah, content urls are only supported by readFile at the moment because they are not regular filesystem url, they belong to other app and you can't do Filesystem tasks on another app file, other than reading it if it was shared, and maybe stat could be implemented with a lot of content resolver code. But should definitely not crash.
I have created a plugin to read a file's name and size from a content uri : https://github.com/ThomasKientz/capacitor-plugin-file-infos
Would be nice to implement it inside FS plugin imo !
Same issue with the copyFile
method. Works perfectly on iOS but not on Android....
This issue is about content urls, that's an android thing, so can't work on iOS. If you mean copyFile doesn't work on Android, report a new issue and provide more information.
What I mean is, that Filesystem.copy()
doesn't work with content://
urls too. This issue doesn't only effect the Filesystem.stat()
method.
My iOS comment is about my expectation, that I can use the same Ionic-App-code for android and iOS. That means passing a Filesystem URI (which I got by some plugin) to any of the FileSystem plugin methods and the Filesystem plugin just does it's magic as it is supposed too. But as often, I have to provide some extra code for Android.... As far as I can tell, in order to copy a file from a content://
URI I'd have to read the file as base64 and then write it to the data
-directory for example. That is tremendous overhead which I'd feel very uncomfortable with. Is there any other way?
I think important information like that, should be displayed way more prominent in the docs. The current hint is not sufficiently clear at all.
Additionally, the Filesystem API supports using full file:// paths, or reading content:// files on Android. Simply leave out the directory param to use a full file path. Source: https://capacitorjs.com/docs/apis/filesystem#understanding-directories-and-files
I found a solution / workaround.
I'm now converting content://
URLs to file://
with the following plugin:
Bug Report
Capacitor Version
npx cap doctor
output:Affected Platform(s)
Description
No issues with
Filesystem.readFile
With
Filesystem.stat
the app crashed and I got the following error in the Android Studio console