Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filesystem.readFile : I cannot read any file except the ones I create with my app, how to fix that? #1838

Closed
TAYBI opened this issue Oct 11, 2023 · 4 comments
Labels

Comments

@TAYBI
Copy link

TAYBI commented Oct 11, 2023

I cannot read any file except the ones I create with my app, how to fix that?

FilePicker.pickFiles({
  multiple: false,
}).then(async (result) => {
 
  const contents = await Filesystem.readFile({
    path: result.files[0].name,
    directory: Directory.Documents,
    encoding: Encoding.UTF8,
  });

I am not able to get any content. it always displays the following error when selecting a file, except for the files created by the application

ERROR Error: Uncaught (in promise): Error: File does not exist
Error: File does not exist
    at returnResult (VM3:772:32)
    at win.androidBridge.onmessage (VM3:747:21)
    at resolvePromise (zone.js:1193:31)
    at zone.js:1100:17
    at zone.js:1116:33
    at _ZoneDelegate.invoke (zone.js:368:26)
    at Object.onInvoke (core.mjs:26262:33)
    at _ZoneDelegate.invoke (zone.js:367:52)
    at Zone.run (zone.js:129:43)
    at zone.js:1257:36
    at _ZoneDelegate.invokeTask (zone.js:402:31)
    at core.mjs:25948:55
@ionitron-bot ionitron-bot bot added the triage label Oct 11, 2023
@jcesarmobile
Copy link
Member

It's an Android limitation, it's documented in the plugin docs that starting in Android 11, they allow to write your own files to documents folder, but don't allow to access other app files.

https://capacitorjs.com/docs/apis/filesystem#android

The only way of reading files from there would be to use a file picker plugin where the user manually picks the file, you can't access them programmatically anymore.

@jcesarmobile jcesarmobile closed this as not planned Won't fix, can't repro, duplicate, stale Oct 11, 2023
@TAYBI
Copy link
Author

TAYBI commented Oct 11, 2023

I am using FilePicker.pickFiles, I want to get the contents of the file after the user selects one

result.files[0].blob appears to be undefined

@jcesarmobile
Copy link
Member

I'm not familiar with that plugin, but it should provide you the file content already, you should not use Filesystem plugin to read it.
Also if you are passing a file path you should not pass a directory.

@ionitron-bot
Copy link

ionitron-bot bot commented Oct 26, 2023

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of the plugin, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Oct 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants