electron icon indicating copy to clipboard operation
electron copied to clipboard

Accessing the filesystem

Open moltenice opened this issue 2 years ago • 12 comments

What's the recommended approach for an Ionic+Capacitor app to access the filesystem via Electron?

There's a couple of options:

  1. Ionic's File plugin: https://ionicframework.com/docs/native/file
  2. Capacitor's Filesystem plugin: https://capacitorjs.com/docs/apis/filesystem

But none of them allow me to access for example my home directory ~.

With pure Electron I can just use fs but that's not an option here as I'd like it to work with Android as well.

A recommended approach and perhaps a code example would be really appreciated as the current docs are only focused on iOS and Android for these plugins.

moltenice avatar Sep 10 '21 14:09 moltenice

https://github.com/digaus/capacitor-community-filesystem

I made a dirty workaround. Works for my project so far. Better would be if we could somehow register the electron part to the original Filesystem Plugin.

Any idea if this would be doable somehow @IT-MikeS? Just pulling the definitions from @capacitor/filesystem and then register the electron part from @capacitor-community/filesystem to it?

That way would could implement @capacitor-community electron versions for the capacitor maintained plugins.

digaus avatar Sep 11 '21 11:09 digaus

I have a plugin like node:fs for capacitor hope it helps you!

https://npmjs.org/package/capacitor-fs

tachibana-shin avatar Sep 16 '21 12:09 tachibana-shin

https://github.com/digaus/capacitor-community-filesystem

I made a dirty workaround. Works for my project so far. Better would be if we could somehow register the electron part to the original Filesystem Plugin.

Any idea if this would be doable somehow @IT-MikeS? Just pulling the definitions from @capacitor/filesystem and then register the electron part from @capacitor-community/filesystem to it?

That way would could implement @capacitor-community electron versions for the capacitor maintained plugins.

Thanks for sharing this, I will take a look.

So in general most Ionic/Capacitor plugins will not work with "@capacitor-community/electron" by default? It seems so strange that accessing the filesystem is highly unsupported cross platform here. Especially when a Cordova plugin exists and would work: https://cordova.apache.org/docs/en/10.x/reference/cordova-plugin-file/

For some reason the Ionic wrapper doesn't work for Electron.

moltenice avatar Sep 23 '21 15:09 moltenice

I have a plugin like node:fs for capacitor hope it helps you!

https://npmjs.org/package/capacitor-fs

Would this work on Android as well?

moltenice avatar Sep 23 '21 15:09 moltenice

Tôi có một plugin như node:fscho tụ điện hy vọng nó sẽ giúp bạn! https://npmjs.org/package/capacitor-fs

Điều này cũng sẽ hoạt động trên Android?

Yes, this plugin working on all platform.

tachibana-shin avatar Sep 24 '21 05:09 tachibana-shin

Thank you very much @digaus and @tachibana-shin for your solutions! They will help me solve this issue :)

Hopefully an official Filesystem solution shows up for capacitor-community/electron at some point.

moltenice avatar Sep 24 '21 08:09 moltenice

My requirement is similar to that of the OP: I want to target Android and Desktop, but I don't need arbitrary access to the whole filesystem. I only want files saved on disk, and it doesn't matter where.

This is the dummy code I'm using:

      await Filesystem.writeFile({
        path: 'test.json',
        data: JSON.stringify("hello world"),
        directory: Directory.Documents,
        encoding: Encoding.UTF8,
      })

If they are saved to disk, I can't find where. Could that be documented?

If they aren't, what would it take to be able to use the @capacitor/filesystem module and save files to disk? I've looked at the capacitor-fs plugin that was previous posted here, but I much prefer the API of the core FS module.

itsMapleLeaf avatar Oct 17 '21 03:10 itsMapleLeaf

My requirement is similar to that of the OP: I want to target Android and Desktop, but I don't need arbitrary access to the whole filesystem. I only want files saved on disk, and it doesn't matter where.

This is the dummy code I'm using:

      await Filesystem.writeFile({
        path: 'test.json',
        data: JSON.stringify("hello world"),
        directory: Directory.Documents,
        encoding: Encoding.UTF8,
      })

If they are saved to disk, I can't find where. Could that be documented?

If they aren't, what would it take to be able to use the @capacitor/filesystem module and save files to disk? I've looked at the capacitor-fs plugin that was previous posted here, but I much prefer the API of the core FS module.

Oh I'll tell you where they'll be saved on Android:

Directory.Documents: /sdcard/Documents/ -- you will see dir Documents as soon as you enter the file manager Directory.Cache: /data/cache -- required root permission

tachibana-shin avatar Oct 17 '21 11:10 tachibana-shin

If you use Directory.Documents as a path on a desktop (Windows 10 and Chrome). Where are the files saved? I notice that it is updated with data but I can't find it on the disk.

BaxAndrei avatar Nov 10 '21 00:11 BaxAndrei

If you use Directory.Documents as a path on a desktop (Windows 10 and Chrome). Where are the files saved? I notice that it is updated with data but I can't find it on the disk.

I also join the question

I found out that the files saved with

await Filesystem.writeFile ({ path: 'AAAAtext222.txt', data: 'This is a test', directory: Directory.Documents, encoding: Encoding.UTF8, });

in the electron assembly for winodws 10

Save to IndexedDB image

I would like to save the files in the root of the program, so where exe. Who knows how?

NeluQi avatar Dec 08 '21 07:12 NeluQi

I added a pull-request to the default Capacitor plugins repo that adds support for Electron to the Filesystem plugin: https://github.com/ionic-team/capacitor-plugins/pull/792

jdgjsag67251 avatar Jan 28 '22 19:01 jdgjsag67251

If you use Directory.Documents as a path on a desktop (Windows 10 and Chrome). Where are the files saved? I notice that it is updated with data but I can't find it on the disk.

I also join the question

I found out that the files saved with

await Filesystem.writeFile ({ path: 'AAAAtext222.txt', data: 'This is a test', directory: Directory.Documents, encoding: Encoding.UTF8, });

in the electron assembly for winodws 10

Save to IndexedDB image

I would like to save the files in the root of the program, so where exe. Who knows how?

Hi mate @NeluQi! Did you find where the files are stored finally?

Estevete avatar Mar 29 '23 17:03 Estevete