How can i access the app's assets folder using fileSystem capacitor

How can i access the assets folder using the built in filesystem capacitor plugin in Ionic 5. I have followed all the filesystem capacitor documentation but nothing seems to do the job. I want to avoid cordova plugins as much as possible.

I have tried setting the path to file:///android_asset/www/assets but failed.

Also tried this:
try {
let ret = await Filesystem.readdir({
path: “”,
directory: FilesystemDirectory.External
});
console.log("Directory: " + ret);
} catch(e) {
console.error(‘Unable to read dir’, e);
}

I don’t believe you can. I would suggest using HttpClient instead. assets isn’t a real folder on the device’s filesystem; it’s burned into your app binary itself.

1 Like

@rapropos Makes sense. Thanks for clearing that up for me. In a previous project I managed to access the assets folder using this Cordova plugin (cordova-plugin-file) and it worked perfectly. But I want to move away from Cordova. Thought I could achieve the same with the capacitor plugin.

Hi,
i’m running through the same issue. Previously, i was working with Cordova, using the File Plugin in order to open a file inside the “www/assets” folder (“file:///android_asset/www/assets” in Android), and it also worked perfectly. I had to migrate form Cordova to Capacitor and now i’m trying to read the same assets folder with the FileSystemPlugin. Have you find a solution/workaround to this issue?
Thanks.

I guess since you didn’t believe me the first time, it’s not likely to do much good for me to repeat it, but there is no “solution/workaround”. assets do not exist from the filesystem’s perspective. They’re an illusion perpetuated by the webview, and you must use HTTP to access them.

Hi.
No, i really believe in your previous answer (mostly because i’m stucked with this problem since several hours :sweat_smile:). Simply i was wondering if the issue’s reporter or someone else could solve this issue using HTTP, as you said.
I’m gonna try to access this assets folder by HttpClient or another plugin. I will reply to this post if I can figure it out.
Thanks you very much!

Have you find any solution/workaround? I need this also…

Nothing has changed here. I’m reluctantly going to close this thread because I don’t see any benefit to anybody in my continuing to repeat myself here.